brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: osascript -e 'id of app' prints the bundle ID of any Mac app

macOS
~/tips/tip-macos-osascript-bundle-id

osascript -e 'id of app "Safari"'

Get an app's bundle identifier for defaults, profiles or scripts in one line.

Lots of Mac tools want a bundle identifier like com.apple.Safari instead of an app name: defaults, configuration profiles, open -b. AppleScript knows it for every app you have.

Ask with a one-liner. Mind the quotes: single quotes around the script, double quotes around the app name.

osascript -e 'id of app "Safari"'

The answer here is com.apple.Safari. It works for third-party apps too, as long as the name matches the app in your Applications folder, for example "Visual Studio Code" or "Firefox".

Once you have the ID you can feed it to other commands. A nice one: open an app by its ID, which keeps working even if someone renamed the app file.

open -b com.apple.Safari

Why AppleScript and not something else? I like it because it’s on every Mac, it needs no extra tools, and the result is clean enough to use in a variable: BID=$(osascript -e 'id of app "Notes"').

One thing to watch: if the name doesn’t match an installed app, macOS may pop up a dialog asking where the app is, and your script waits for it. Spell the name exactly as Finder shows it, without .app, and check a new name by hand before you put it in a script.

Further reading: osascript.1 man page, open.1 man page

More macOS tips System Settings > Accessibility > Hover Text > When using the pointer A Smart Folder in Notes collects notes by tag, checklist or date Type # in a Mac note to tag it, then filter by tag in the sidebar tmutil isexcluded ~/Projects/app/node_modules Crop an image in Preview by dragging a frame and clicking Crop All macOS tips (99) All topics

Link