Getting a Bundle ID using an Alfred File Action
For some automation that I”m writing, I need to get the Bundle ID for some Mac applications.
The easiest way to do this is with AppleScript:
osascript -e 'id of app "{Application Name}"'
This can easily be turned into a bash script such as `bundle-id-of` like this:
#!/usr/bin/env bash
osascript -e 'id of app "'"$1"'"'
And we can now obtain the bundle id on the command line:
Using Alfred
As I’m lazy and don’t want to type application names, it’d be easier if I could just select the application in Finder (or in Alfred itself) and run an Alfred workflow triggered by a File Action.
File Actions allow you to press ⌥⌘space and select from a list of options.
I was about to write a workflow, when it occurred to me that I should get the Alfred Gallery and lo-and-behold, Alan He had already written AppID.
I installed it and now I can very easily get the Bundle ID in Alfred by finding the application, pressing the right arrow key and selected App ID.
Pressing enter will 1Password’s Bundle ID (com.1password.1password) to the clipboard and show a notification:
Problem solved. The Alfred Gallery certainly makes it easier to install new workflows.