Skip to content

fix(app-management): use simctl --json instead of a shell pipe for simulator app list - #486

Closed
Mochxd wants to merge 1 commit into
appium:mainfrom
Mochxd:fix/simctl-listapps-json
Closed

fix(app-management): use simctl --json instead of a shell pipe for simulator app list#486
Mochxd wants to merge 1 commit into
appium:mainfrom
Mochxd:fix/simctl-listapps-json

Conversation

@Mochxd

@Mochxd Mochxd commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Problem

Listing apps on an iOS simulator passes a shell pipe as spawn arguments:

exec('xcrun', ['simctl', 'listapps', udid, '|', 'plutil', '-convert', 'json', '-o', '-', '-'])

teen_process.exec spawns without a shell, so |, plutil and the rest are handed to simctl listapps as literal arguments instead of forming a pipeline. The simulator app list never gets converted to JSON, so appium_app_lifecycle action=list and name-based app resolution fail on local simulator sessions.

This regressed in #423, which converted the original child_process.exec shell string (xcrun simctl listapps "$udid" | plutil -convert json -o - -) into an argv array. The pipe was preserved as an argument.

Fix

Ask simctl for JSON directly with --json, which is what prepare-ios-simulator.ts already does when it reads the simulator app list:

https://github.com/appium/appium-mcp/blob/main/src/tools/ios/prepare-ios-simulator.ts#L180

This drops the plutil dependency entirely and keeps the two simulator code paths consistent.

Test

Added src/tests/tools/app-management/list-apps.test.ts covering the simulator branch:

  • simctl is invoked as ['simctl', 'listapps', udid, '--json'], with no | or plutil argument
  • the returned payload is normalized into package/app name pairs

'-',
'-',
]);
const {stdout} = await exec('xcrun', ['simctl', 'listapps', udid, '--json']);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to call the simctl via https://appium.github.io/appium-xcuitest-driver/12.3/reference/execute-methods/#mobile-simctl instead of direct simctl to make the same logic work on local/remote.

Let me do the update instead

@KazuCocoa KazuCocoa Aug 12, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, did you succeed in getting JSON format with this...? My local didn't return valid JSON with the --json such as xcrun simctl listapps C874BE6A-7424-4493-AAFB-3BE54C3942AE --json (vanilla xcrun as well)

#487 instead which worked on my local

@KazuCocoa KazuCocoa mentioned this pull request Aug 12, 2026
@KazuCocoa

Copy link
Copy Markdown
Member

Let me merge #487 as the json format didn't work expectedly on my env even vanilla simctl command. It might have xcode version deps as well

@KazuCocoa

Copy link
Copy Markdown
Member

thank you for the finding

@KazuCocoa KazuCocoa closed this Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants