I want to find if an application is installed using AppleScript
.
The application can have different versions installed in the same PC.
Hence, the name of the application is in the format "FooBar vXX.XX"
Now, when I tried
tell application "Finder" to get application "FooBar"
The script launched a pop up, asking the user to find the app manually. Because, I didn't give the full name of the application - which includes the version number.
My query is, how can I find the installed application without its full name? This is necessary because I don't know which version is installed.
Can I use a regex in this case - How do I use it in this example?
You can use spotlight on the command line by using a do shell script command. You can ask spotlight for a list of all application whose name begins with a certain string. Applications do have 'com.apple.application-bundle' value for the 'kMDItemContentType' key. We can use kMDItemFSName to match with the file name. There is also the kMDItemDisplayName attribute you can use. Here an example of using the kMDItemFSName
every paragraph of (do shell script "mdfind 'kMDItemContentType == com.apple.application-bundle && kMDItemFSName == FooBar*'")
Another way is when you know the bundle identifier of the application. Most of the time the bundle identifier stays the same through all versions of the application, even mayor updates. For instance Terminal.app does have an bundle identifier com.apple.Terminal which is the same for all versions. The search key is kMDItemCFBundleIdentifier:
every paragraph of (do shell script "mdfind 'kMDItemCFBundleIdentifier == com.apple.Terminal'")
note: search strings are case sensitive; foobar is not the same as FooBar
If you don't know what the bundle identifier of the application is you can do this with AppleScript:
tell application "FooBar" to return id