MandyW
MandyW

Reputation: 1147

Is there a way to close the iOS Simulator from the command line?

Is there any way to quit the iOS Simulator via a command line script?

Background:

I am setting up a Continous Integration environment to enable iOS builds to compile and be tested automatically. As part of this I am running scripts using Apple's UI Automation tool within Instruments.

I've managed to automate the execution of the scripts on the iOS Simulator by running Instruments from the command line BUT now I now want to automate quitting of the Simulator.

I have tried some Apple Script similar to this post: How can I reset the iOS Simulator from the command line? but get the error "Access for assistive devices is disabled". Hopefully, there is a simpler way?

Upvotes: 14

Views: 16364

Answers (5)

Danyal Aytekin
Danyal Aytekin

Reputation: 4215

For Xcode 7+ the command is killall Simulator.

Upvotes: 33

Grigory Entin
Grigory Entin

Reputation: 161

Try this:

osascript -e 'tell app "iOS Simulator" to quit'

Upvotes: 14

djromero
djromero

Reputation: 19641

killall "iOS Simulator" in the Terminal will close it.

Also, you can launch it with iphonesim to have more control over it, including modifying the source to your needs.

Upvotes: 22

Michael Dodwell
Michael Dodwell

Reputation: 91

Pulling some of the commands together for XCode 6:

killall "iOS Simulator" 

xcrun simctl list | grep Booted | awk -F "[()]" '{ for (i=2; i<NF; i+=2) print $i }' | grep '^[-A-Z0-9]*$' | xargs -I uuid xcrun simctl shutdown uuid

xcrun simctl list | awk -F "[()]" '{ for (i=2; i<NF; i+=2) print $i }' | grep '^[-A-Z0-9]*$' | xargs -I uuid xcrun simctl erase uuid

open /Applications/Xcode.app/Contents/Developer/Applications/iOS\ Simulator.app

Upvotes: 5

Dennis Bliefernicht
Dennis Bliefernicht

Reputation: 5157

Based on that script you could create it like this:

tell application "iPhone Simulator"
    activate
end tell

tell application "System Events"
    tell process "iPhone Simulator"
        tell menu bar 1
            tell menu bar item "iOS Simulator"
                tell menu "iOS Simulator"
                    click menu item "Quit iOS Simulator"
                end tell
            end tell
        end tell
    end tell
end tell

The assistive devices error would occur on this as well. To fix that you need to go to System settings, Universal access and check "Enable access for assistive devices"

Upvotes: -1

Related Questions