Wouldn’t it be more useful to search for the application name? (Usually, when I don’t know if an app is installed, I don’t know the BundleID either.)
For that you could say
id of application "application name"
Example:
try
set theApp to "textmate"
# Force-refresh database; for testing only
do shell script "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -r -f -apps user,local,system"
set theID to id of application theApp
display alert "Application “" & theApp & "” is installed.\nBundleID: " & theID
on error
display alert "No application “" & theApp & "” found!"
end try
Notes:
- The “do shell script” force-refreshes the LaunchServices database for apps. (May take 30 seconds or so.) I have included it for testing, but for normal usage it should not be necessary, since the database gets auto-updated regularly.
- The “on error … display alert” isn’t strictly necessary either. Normally, if the app is not found, you get the “Choose Application” window. However, in some occasions the “Choose Application” window does not show up.
Edit:
I refined the AppleScript a bit and wrapped it in a KM macro “Get Bundle ID”.