30

I want to use Python and atomac module to trigger an application in macOS like following scripts:

atomac.launchAppByBundleID()
app_win = atomac.getAppRefByBundleId(app_bundle_ID)

But I don't know how to get the Bundle ID (app_bundle_ID) of the application.

pkamb
  • 33,281
  • 23
  • 160
  • 191
Qing
  • 1,019
  • 1
  • 8
  • 6

3 Answers3

71

I use two methods to get the bundler ID:

osascript -e 'id of app "SomeApp"'

and

mdls -name kMDItemCFBundleIdentifier -r SomeApp.app
linusg
  • 6,289
  • 4
  • 28
  • 78
Qing
  • 1,019
  • 1
  • 8
  • 6
  • 3
    Good stuff. I build on your command to also 1. Go to /Applications 2. Get Bundle ID of app 3. copy it to the clipboard, while still displaying it 4. Go back to original directory (I have it set up in TextExpander so the cursor is positioned at "SomeApp"): cd /Applications && osascript -e 'id of app "Visual Studio Code"' | pbcopy && pbpaste && cd - >/dev/null && printf '\n(copied to clipbord)\n\n' – Gandalf Saxe Jun 14 '19 at 14:49
  • 1
    If you want to use this in a bash script with a variable, you shall get problems with the single quotes. I did it with `osascript -e 'id of app "'"$1"'"'` to get my app name injected as variable. – Martin Braun Feb 06 '22 at 10:07
  • In my case, I have mutiple versions app, now I run command `open -b myAppId` it will open previous version instead of latest version. How can I fix it? Thanks – mqliutie Jul 22 '22 at 03:37
7

if you just need it to launch the app look in the app's info.plist file. the file is in the app bundle in the Contents directory. This works for a lot of apps.

Yup
  • 71
  • 2
3

As we know, bundle id is located in the info.plist of an app, so both PlistBuddy and defaults could help

/usr/libexec/PlistBuddy -c 'print CFBundleIdentifier' /Applications/Xcode.app/Contents/Info.plist
or
defaults read /Applications/Xcode.app/Contents/Info.plist CFBundleIdentifier

which prints

com.apple.dt.Xcode

DawnSong
  • 4,752
  • 2
  • 38
  • 38