Monday, December 23, 2013

Xcode running instruments from commandLine in the actual Device

1) run terminal as Admin (sudo -s).
2) point to the directory where scripts are residing (/users/sj/desktop/scripts/.... etc).
3) Use the full path for the app
4) Run the following command

instruments -w 17cbebfa26acxxxxxxxxxxxxxxxxx -t  /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate /var/mobile/Applications/A51C31B7-6566-46FB-XXXX-XXXXXXXXXXXX/abc.app  -e UIASCRIPT Script1.js


the one next to -w is the UDID of the device
after -t it is the full Path for the instruments (note this might change for different versions of Xcode. the above code works for xcode 5.0.2)
after tracetemplate -- the one starting with /var is the full path of the APP(If you get error like unable to find CFBundleidentifier then specify the full path for the app otheriwse just the app name should suffice without full path)
after UIASCRIPT it is the name of the script.

optional: To specify where to store the trace output(i.e log) please specify the following
-e UIARESULTSPATH fullPath

The above configuration worked for me. Without Admin rights and without running the script from the folder or without specifying the full app path i got the following errors.

1. Argument 'UIASCRIPT' does not point to a valid script. Using script defined in template.
2. Automation Instrument ran into an exception while trying to run the script.  UIANoScriptToRun
3. Connection peer refused channel request for "com.apple.instruments.server.services.wireless"; channel canceled <DTXChannel: 0x7fba2b94a7c0>
4.unable to find bundleidentifier for abc.app