Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking up user Library folders on OSX from a bash script?

Tags:

bash

macos

Apparently the correct way to find the place to store an application's data in OSX is to call in ObjectiveC

NSArray* theDirs = [[NSFileManager defaultManager] 
    URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask]

Normally that would return /Users/<username>/Library/Application Support

How can I get that from bash script? Yes I know I could just do this

DIR="${HOME}/Library/Application Support"

But that's not really the correct way to do it. You're supposed to ask the OS so it can give you the actual directory. (might be on the network for example?).

Yes, I suppose I could write a small ObjectiveC app just to return that path but I'm assuming there's got to be a standard way to do this?


1 Answers

One way is use AppleScript and its System Events helper application. osascript allows you to run AppleScript from the command line:

DIR="$(osascript \
      -e 'tell application "System Events"' \
      -e 'get POSIX path of (path to application support folder from user domain)' \
      -e 'end tell')"
echo $DIR

--> /Users/nad/Library/Application Support
like image 87
Ned Deily Avatar answered Oct 17 '25 02:10

Ned Deily