33

How is possible to find quickly the document folder (in the mac) of an App when I'm using the simulator? When I need to explore the document folder during the simulation of the App now I use a variable of the App to find the document folder path and I read the path during the debug (using a variable) but I think is not the best solution.

Honey
  • 24,125
  • 14
  • 123
  • 212
Lorenzo
  • 2,987
  • 2
  • 23
  • 48
  • If you're developing only one app then there is only one folder beyond ~Libraries/Application Support/iPhoneSimulator (I have to check the path). – ott-- Mar 12 '16 at 22:27
  • the path seems doesn't exist.. – Lorenzo Mar 12 '16 at 22:30
  • Try `~/Library/Application\ Support/iPhoneSimulator` – L3viathan Mar 12 '16 at 23:19
  • nothing to do.. the path doesn't exist. I solved using the mac App SimulationManager. Thanks anyway – Lorenzo Mar 12 '16 at 23:20
  • 1
    See `~/Library/Application Support/iPhone Simulator/7.1/Applications` when you're developing for 7.1. When you're developing for 8.0 then check for 8.0. When you change to a directory, you can check for other dirs available by pressing `~/Library/App`. – ott-- Mar 12 '16 at 23:41
  • Try the SimulatorManager. It's a Mac app that display an icon in the task bar with all simulator devices in the menu and allow you to browse apps document sandbox installed on each simulator. [http://tue-savvy.github.io](http://tue-savvy.github.io) – mikyl Mar 12 '16 at 22:26
  • But the App is compatible only with XCode 6 and I use XCode7... – Lorenzo Mar 12 '16 at 22:30
  • It works for me on XCode 7 / El capitan. You need to compile and install it. – mikyl Mar 12 '16 at 22:37
  • Yes I'm trying it... it seems more easy than the plugin... – Lorenzo Mar 12 '16 at 22:42
  • Yes it works correctly ... is a little bit slow at opening but it works.. thanks! – Lorenzo Mar 12 '16 at 22:51

4 Answers4

115

Set and hit a breakpoint in the app, and write the following in the Xcode Console (next to the Variables View):

po NSHomeDirectory()

Then in Finder hit Shift+CMD+G, paste the path returned above without the quotation marks and hit enter.

Johan
  • 2,262
  • 1
  • 20
  • 24
  • This throws a compiler error for me; adjusting it to `var homeDir = NSHomeDirecotry; print(homeDir)` (or examining the value of homeDir at a break point) works though. – Alex Hall Feb 27 '17 at 17:38
  • 4
    @AlexHall This answer says to write this command **in the console** while paused at a break point. I misread it at first too and thought it meant to put this command in your code. – BigHeadCreations May 10 '17 at 05:15
16

Open up Terminal.app and run:

xcrun simctl get_app_container booted [app identifier]

You can even setup an alias to change to the directory, like:

alias cdmyapp='cd $(xcrun simctl get_app_container booted com.mycompany.myapp)'
Jeremy Huddleston Sequoia
  • 21,715
  • 5
  • 69
  • 82
  • 3
    I like the alias idea! But this is just the bundle folder, not the Documents folder. – nickcheng Apr 12 '17 at 06:05
  • This is awesome. May I know where can I get the list of other such functions (e.g get_app_container)? I'm basically looking to fetch Documents Directory from command line. Any Help? – Rohit saraf Apr 20 '17 at 09:20
  • 2
    This returns the .app bundle not the documents/data directory as the question asks – Mike Weller Apr 24 '17 at 15:18
  • Great answer, in the modern Xcode environment I think this is probably the fastest way. – Jeremy Jul 24 '17 at 15:32
  • cd $(xcrun simctl get_app_container booted [app identifier] data) to get to the documents folder – Dan Carlson Sep 08 '19 at 00:04
  • 2
    `open $(xcrun simctl get_app_container booted com.guidebook.guidebook data)/Documents` to open de documents folder. Notice `data` and `/Documents`. – henrique Oct 08 '19 at 15:20
4

I have 2 solution

  • Simpholders or free and open source alternative OpenSim
  • A simple script that opens the finder window with the recently launched application on the iOS simulator

deviceId=$(xcrun simctl list devices | grep Booted | sed -n 's/^.([A-F0-9]{8}-([A-F0-9]{4}-){3}[A-F0-9]{12}).$/\1/p') applicationFolder=~/Library/Developer/CoreSimulator/Devices/$deviceId/data/Containers/Data/Application/ applicationFolder=$applicationFolder$(ls -Art $applicationFolder | tail -n 1) open $applicationFolder

Tomasz Rejdych
  • 390
  • 3
  • 7
2

If you're using ZSH, you could try this script. https://gist.github.com/nickcheng/cbc0717d2c9f79613cf2c042503b5422

nickcheng
  • 516
  • 3
  • 22