条件 説明 -n 文字列が存在すれば真 -z 文字列が存在しなければ真 -d ディレクトリが存在すれば真 -f ファイルが存在すれば真 -s ファイルが存在し、かつファイルサイズが0でなければ真 -e ディレクトリかファイルが存在すれば真 -r ファイルが読み込み可能であれば真 -w ファイルが書き込み可能であれば真 -x ファイルが実行可能であれば真
http://www.boaro.jp/linux/bash/bash_script.html
iOS シミュレータが直接起動できないっぽい
むかしは直接起動できたけど、管理方法がアレコレ変わって直接起動が出来ない。
iOS のプロファイル(OSイメージ)一覧を出力する
iOS のプロファイル管理は 次の場所にある。
~/Library/Developer/CoreSimulator/Devices/
ちなみに、私のOSXでは次のようになっていた。
takuya@~/Desktop$ ll ~/Library/Developer/CoreSimulator/Devices/ total 8 drwxr-xr-x 4 takuya staff 136 5 21 22:57 16D197CE-8B41-45C6-A9BD-EB7F12D6FD95 drwxr-xr-x 4 takuya staff 136 5 21 22:57 18F87714-EB72-47E0-AEAC-81DCE7C6BD57 drwxr-xr-x 4 takuya staff 136 5 21 22:57 24195A52-91D1-469D-98E8-B9FBE4F957EB drwxr-xr-x 4 takuya staff 136 5 26 22:45 286C2C87-9A6E-4FBB-AF33-FC2E61051A6E drwxr-xr-x 4 takuya staff 136 5 21 22:57 4AD7F520-0550-4E98-8961-4E74EC1A9577 drwxr-xr-x 4 takuya staff 136 5 21 22:57 4D18598F-FE49-4EF0-878D-F464B64AD728 drwxr-xr-x 4 takuya staff 136 5 21 22:57 549A15D3-3496-44C9-9409-C1D934116F1A drwxr-xr-x 4 takuya staff 136 5 21 22:57 5984338B-FB8F-43E9-8E48-559BC9C9F57D drwxr-xr-x 4 takuya staff 136 5 21 22:57 6F4C1121-997C-40D4-A406-7D32C6BE8829 drwxr-xr-x 4 takuya staff 136 5 21 22:57 822C303E-DD38-4B6D-9C4A-0C3558896684 drwxr-xr-x 4 takuya staff 136 5 21 22:57 E5025B7C-0A30-40CB-99F9-131017209AA6 -rw-r--r-- 1 takuya staff 5819 5 25 13:15 device_set.plist
でもこんなが見られても、嬉しい人はあまりいないと思う。
イメージ一覧を出力する simctl
先ほどのディレクトリの中身は次のコマンドで行う。*1
xcrun simctl list
list をすることで一覧を見ることが出来ます。
takuya@~/Desktop$ xcrun simctl list
== Device Types ==
iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s)
iPhone 5 (com.apple.CoreSimulator.SimDeviceType.iPhone-5)
iPhone 5s (com.apple.CoreSimulator.SimDeviceType.iPhone-5s)
iPhone 6 (com.apple.CoreSimulator.SimDeviceType.iPhone-6)
iPhone 6 Plus (com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus)
iPhone 6s (com.apple.CoreSimulator.SimDeviceType.iPhone-6s)
iPhone 6s Plus (com.apple.CoreSimulator.SimDeviceType.iPhone-6s-Plus)
iPad 2 (com.apple.CoreSimulator.SimDeviceType.iPad-2)
iPad Retina (com.apple.CoreSimulator.SimDeviceType.iPad-Retina)
iPad Air (com.apple.CoreSimulator.SimDeviceType.iPad-Air)
iPad Air 2 (com.apple.CoreSimulator.SimDeviceType.iPad-Air-2)
iPad Pro (com.apple.CoreSimulator.SimDeviceType.iPad-Pro)
Apple TV 1080p (com.apple.CoreSimulator.SimDeviceType.Apple-TV-1080p)
Apple Watch - 38mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-38mm)
Apple Watch - 42mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-42mm)
== Runtimes ==
iOS 9.0 (9.0 - 13A344) (com.apple.CoreSimulator.SimRuntime.iOS-9-0)
iOS 9.3 (9.3 - 13E230) (com.apple.CoreSimulator.SimRuntime.iOS-9-3)
tvOS 9.2 (9.2 - 13Y227) (com.apple.CoreSimulator.SimRuntime.tvOS-9-2)
watchOS 2.2 (2.2 - 13V143) (com.apple.CoreSimulator.SimRuntime.watchOS-2-2)
== Devices ==
-- iOS 9.0 --
iPhone 4s (4AD7F520-0550-4E98-8961-4E74EC1A9577) (Shutdown)
iPhone 5 (549A15D3-3496-44C9-9409-C1D934116F1A) (Shutdown)
iPhone 5s (286C2C87-9A6E-4FBB-AF33-FC2E61051A6E) (Booted)
iPhone 6 (4D18598F-FE49-4EF0-878D-F464B64AD728) (Shutdown)
iPhone 6 Plus (E5025B7C-0A30-40CB-99F9-131017209AA6) (Shutdown)
iPhone 6s (5984338B-FB8F-43E9-8E48-559BC9C9F57D) (Shutdown)
iPhone 6s Plus (6F4C1121-997C-40D4-A406-7D32C6BE8829) (Shutdown)
iPad 2 (24195A52-91D1-469D-98E8-B9FBE4F957EB) (Shutdown)
iPad Retina (16D197CE-8B41-45C6-A9BD-EB7F12D6FD95) (Shutdown)
iPad Air (822C303E-DD38-4B6D-9C4A-0C3558896684) (Shutdown)
iPad Air 2 (18F87714-EB72-47E0-AEAC-81DCE7C6BD57) (Shutdown)
-- iOS 9.3 --
-- tvOS 9.2 --
-- watchOS 2.2 --
== Device Pairs ==
先ほど~/Library で確認したデバイスがチャント確認できます。こちらは、iOS と 機種名で強い
xcrun が見つからない時は。
xcrun は xcode 内蔵のコマンドを実行します。simctl も xcrun も次の場所にありました。
/Applications/Xcode.app/Contents/Developer/usr/bin
シミュレータを起動する(バックグラウンド)
シミュレータを起動するには次のようにします。
xcrun simctl shutdown 286C2C87-9A6E-4FBB-AF33-FC2E61051A6E
すると xcrun simctl の結果が次のように変わります。
iPhone 5s (286C2C87-9A6E-4FBB-AF33-FC2E61051A6E) (Shutdown)
iPhone 5s (286C2C87-9A6E-4FBB-AF33-FC2E61051A6E) (Booted)
でも、GUIは起動しません。
Simulator のGUIを起動する。
Simulator app を起動するには、次のように変わります。
open -a "Simulator" --args 286C2C87-9A6E-4FBB-AF33-FC2E61051A6E
これで無事にシミュレータが起動します。
やったね。

simctl は他にも次のように使える
Usage: simctl [--noxpc] [--set <set path>] <subcommand> ... | help [subcommand]
Command line utility to control the Simulator
For subcommands that require a <device> argument, you may specify a device UDID
or the special "booted" string which will cause simctl to pick a booted device.
If multiple devices are booted when the "booted" device is selected, simctl
will choose one of them.
Subcommands:
create Create a new device.
delete Delete a device or all unavailable devices.
pair Create a new watch and phone pair.
unpair Unpair a watch and phone pair.
pair_activate Set a given pair as active.
erase Erase a device's contents and settings.
boot Boot a device.
shutdown Shutdown a device.
rename Rename a device.
getenv Print an environment variable from a running device.
openurl Open a URL in a device.
addphoto Add photos to the photo library of a device.
addvideo Add videos to the photo library of a device.
install Install an app on a device.
uninstall Uninstall an app from a device.
get_app_container Print the path of the intsalled app's container
launch Launch an application by identifier on a device.
spawn Spawn a process on a device.
list List available devices, device types, runtimes, or device pairs.
icloud_sync Trigger iCloud sync on a device.
help Prints the usage for a given subcommand.
個人的には openurl とかめっちゃ楽じゃん。と思った。
iOS 楽しい。
*1: 調査中にパスが覚えられないとか行ってるqiitaの記事見つけてそっ閉じした。