xcrun simctl get_app_containerは、シミュレータにインストールされたアプリの、.appバンドルやデータ保存先のパスを取得するサブコマンドである。

基本的な使い方

get_app_container <device> <app bundle identifier> [<container>]の形式で実行する。 <container>を省略するとapp.appバンドル本体)のパスが表示される。

$ xcrun simctl get_app_container "TIL Container Test" com.apple.mobilesafari
/Library/Developer/CoreSimulator/Volumes/iOS_23F77/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 26.5.simruntime/Contents/Resources/RuntimeRoot/Applications/MobileSafari.app

プリインストールされているSafariの場合、パスはランタイムのシステム領域を指す。

dataでアプリのデータ保存先を取得する

dataを指定すると、アプリが作成したファイルなどが保存されるディレクトリのパスが取得できる。

$ xcrun simctl get_app_container "TIL Container Test" com.apple.mobilesafari data
/Users/xxx/Library/Developer/CoreSimulator/Devices/<UUID>/data/Containers/Data/Application/<UUID>

アプリごとに固有のUUIDディレクトリが割り当てられており、そのアプリのDocuments・Library・tmpなどが配置される。

groupsでApp Groupのコンテナパスを一覧表示する

groupsを指定すると、そのアプリが参加している全てのApp Groupのコンテナパスが、グループ識別子とパスをタブ区切りにした形式で一覧表示される。

$ xcrun simctl get_app_container "TIL Container Test" com.apple.mobilesafari groups
group.com.apple.BrowserKit	/Users/xxx/Library/Developer/CoreSimulator/Devices/<UUID>/data/Containers/Shared/AppGroup/<UUID>
group.com.apple.tipsnext	/Users/xxx/Library/Developer/CoreSimulator/Devices/<UUID>/data/Containers/Shared/AppGroup/<UUID>
group.com.apple.sports	/Users/xxx/Library/Developer/CoreSimulator/Devices/<UUID>/data/Containers/Shared/AppGroup/<UUID>

Safariは複数のApp Groupに参加しており、それぞれ別のコンテナディレクトリが割り当てられていることが分かる。

ヘルプに記載の「特定のApp Groupを指定する」機能は動作しない

ヘルプには、<container>にApp Groupの識別子(例: group.com.apple.BrowserKit)を直接指定すると、そのグループ単体のコンテナパスを取得できると記載されている。

container   Optionally specify the container. Defaults to app.
  app                 The .app bundle
  data                The application's data container
  groups              The App Group containers
  <group identifier>  A specific App Group container

実際に試したところ、appdatagroups以外の値(実在するApp Group識別子を含む)を指定すると、いずれもヘルプ全体が再表示されるだけのエラーになった。

$ xcrun simctl get_app_container "TIL Container Test" com.apple.mobilesafari group.com.apple.BrowserKit
Print the path of the installed app's container
Usage: simctl get_app_container <device> <app bundle identifier> [<container>]
...

特定のApp Groupのパスだけを取得したい場合は、groupsで一覧を取得してから、目的の識別子に対応する行を抜き出す必要がある。

$ xcrun simctl get_app_container "TIL Container Test" com.apple.mobilesafari groups | grep "group.com.apple.BrowserKit" | cut -f2

存在しないbundle identifierを指定するとエラーになる

インストールされていないアプリのbundle identifierを指定すると、エラーになる。

$ xcrun simctl get_app_container "TIL Container Test" com.til.nonexistent.app
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2):
The operation couldn't be completed. No such file or directory
No such file or directory

活用例: アプリのデータを直接検査する

dataで取得したパスに対して、通常のファイル操作コマンドを組み合わせると、GUIを操作せずにアプリの内部データを調査できる。

$ DATA_DIR=$(xcrun simctl get_app_container "TIL Container Test" com.example.app data)
$ find "$DATA_DIR/Documents" -type f

CIでのテスト後に、アプリが期待通りのファイルを生成しているかを検証する際にも活用できる。