├── LICENSE ├── README.md ├── get-device.awk ├── pretty-list.awk ├── simulator └── test ├── test.rb └── test_create.rb /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Dave Lyon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # simulator - simctl beautifier 2 | 3 | Xcode 6 ships with a nifty little utility called `simctl` that allows easy management of simulators. It even lets you give them nice, readable names like "iOS7 iPad" when creating them! It does *not* however, let you reference them by those names for other commands. This means that scripting is hard because you must know or parse out the identifier for the simulator you want to target, instead of being able to refer to it by a consistent name. `simulator` wraps simctl and extends it just a bit to make it easier to work with. 4 | 5 | # Use cases 6 | 7 | Originally inspired by trying to create a test script that every dev could run without modifying. In order to do that with `simctl`, you'd need to know the UDID which would be different on each machine. 8 | 9 | For the original case, I scripted creating 2 simulators ZTestsimulator81, ZTestSimulator71, to run tests cleanly from the command line without running the risk of clearing a developers current development data. 10 | 11 | I created this wrapper after realizing that identifying and managing simulators by name would make any scripting task easier. 12 | 13 | # Install 14 | 15 | ## Homebrew 16 | 17 | ```sh 18 | brew tap davelyon/tap 19 | brew install simulator 20 | ``` 21 | 22 | ## Other Options 23 | 24 | Open to suggestions, but possibly the easiest is just to clone the repo and ensure that the directory ends up in your PATH 25 | 26 | # Examples: 27 | 28 | ``` sh 29 | simulator create "My Test Simulator" iPhone-5s iOS-8-2 30 | # A9F00BFD-66D5-4E78-8E18-C08DC3772C28 31 | 32 | simulator list 33 | # == Devices == 34 | # -- iOS 8.2 -- 35 | # iPhone 4s (4183E129-01F2-47C4-941C-E7DE6AB69F5F) (Shutdown) 36 | # iPhone 5 (9547A985-3409-48B0-94AF-2C9639DE76ED) (Shutdown) 37 | # iPhone 5s (BEC8FB3E-475D-49DC-9119-3CF007F574E7) (Shutdown) 38 | # My Test Simulator (A9F00BFD-66D5-4E78-8E18-C08DC3772C28) (Shutdown) 39 | 40 | simulator reset "My Test Simulator" 41 | simulator destroy "My Test Simulator" 42 | ``` 43 | -------------------------------------------------------------------------------- /get-device.awk: -------------------------------------------------------------------------------- 1 | # Find a device by name 2 | 3 | { 4 | gsub(/^[ \t]+/,""); 5 | if($0 ~ simname) { 6 | match($0,/\([^)]+/); 7 | printf "%-20s\n", substr($0, RSTART+1, RLENGTH-1) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /pretty-list.awk: -------------------------------------------------------------------------------- 1 | function bold(str) { 2 | return sprintf("%c[1;30m%s%c[0m\n", 27, str, 27) 3 | } 4 | { 5 | gsub(/^[ \t]+/,""); 6 | simulator = match($0, /^\s*([^-=][^(]+)/); 7 | # If the line begins with - or =, it's a header, otherwise it's formatted like: 8 | # Some Name (Data) (Data) 9 | if(simulator != 0) { 10 | # Left align the name and set column width to 20 to align the rest of the lines 11 | printf "%-20s\t%s\n", substr($0, RSTART, RLENGTH), substr($0, RLENGTH) 12 | } else { 13 | # If it's a header, just print it 14 | printf bold($0) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /simulator: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | AWKPATH=$(dirname $0) 5 | 6 | # Usage: 7 | # list [devices|devicetypes|runtimes] - show all SDKs, Devices, and Device Types 8 | # find "Device Name" - find a device with the given name and print the identifier 9 | # reset "Device Name" - reset a device with the given name 10 | # create "Device Name" [iOS-8-X|iOS-7-X] [iPhone-4s|iPhone-5|Resizable-iPhone|...(See device types)] 11 | # destroy "Device Name" - Destroy the device (delete it) 12 | # delete "Device Name" - (Matches underlying simctl command) 13 | 14 | # Get a simulator by name, e.g. 15 | # iPhone 4s -> 124EA-6CDF... 16 | function simulator_id_from_name() { 17 | shift 18 | simname="$@" 19 | SIMULATOR_ID=$(xcrun simctl list devices | awk -f $AWKPATH/get-device.awk -v simname="$simname") 20 | } 21 | 22 | command="$1" 23 | case "$command" in 24 | "" | "-h" | "--help" ) 25 | cat <