Get Browser Version

Hi, question:
How can I get the browser version?

Thought about creating a macro that
1.- taps Safari> About in the menu
2.- clicks and starts dragging in the modal, selecting "Version X.XX.XX etc"

and doing something similar for Chrome

and integrate it with this one

any other ways?

EDIT: Also could save the browser version as hardcoded text, but it'd need constant updating

You can get the first number with this shell command (all one line):

defaults read /Applications/Safari.app/Contents/Info CFBundleShortVersionString

will give you "12.1.1".

and you can get the second with this shell command (all one line)

defaults read /Applications/Safari.app/Contents/Info CFBundleVersion

will give you "14607.2.6.1.1".

You can get the same info from Chrome by replacing the Safari part with this:

/Applications/Google\ Chrome.app/Contents/Info

or this

"/Applications/Google Chrome.app/Contents/Info"

e.g.:

defaults read "/Applications/Google Chrome.app/Contents/Info" CFBundleShortVersionString

Keyboard Maestro can save shell script output to Keyboard Maestro variables.

1 Like

Huge thanks!! Awesome to know this tip!

You could even get them both in one shell command, like this:

#!/bin/zsh -f

defaults read "/Applications/Safari.app/Contents/Info" \
| egrep -i 'CFBundleVersion|CFBundleShortVersionString' \
| sort \
| awk -F'"' '//{print $2}'

which will give you this:

12.1.1
14607.2.6.1.1

but now I'm just showing off :wink: and it's actually probably more difficult to deal with and not nearly as useful in practice.

1 Like

thanks!
With your script didn't need to add the external script I had linked to in the first post, so it's just this:

Nice!

Hey Guys,

I don't like using the defaults system when getting this kind of thing, because in my experience it occasionally can hang for 1 (or more) seconds before returning a value.

Here's a macro that will run virtually instantly whether Safari is running or not.

Get Safari's Long Version String.kmmacros (5.4 KB)

if you can make due with the short version string then it's easier still using AppleScript.

--------------------------------------------------------
# Safari Short Version String
--------------------------------------------------------

tell application "Finder" to set safariAppAlias to ¬
   (application file id "com.apple.Safari") as alias

tell application "System Events" to ¬
   set safariShortVersion to short version of safariAppAlias

--------------------------------------------------------
# Google Chrome Short Version String
--------------------------------------------------------

tell application "Finder" to set chromeAppAlias to ¬
   (application file id "com.google.Chrome") as alias

tell application "System Events" to ¬
   set chromeShortVersion to short version of chromeAppAlias

--------------------------------------------------------

If the browser is running then we can get even simpler:

--------------------------------------------------------

tell application "Safari"
   set shortVersionString to version
end tell

--------------------------------------------------------

tell application "Brave Browser"
   set shortVersionString to version
end tell

--------------------------------------------------------

-Chris

1 Like

I believe you can retrieve the version of any application, regardless of whether it is scriptable or not, or whether it is running or not, by referencing it through its bundle identifier:

version of application id "com.apple.safari"
    --> "12.1.1"

version of application id "com.google.chrome"
    --> "75.0.3770.100"

This ought not to launch the application.

2 Likes

I have been using a macro/script for several years now that will get the version of any app (including browsers) AND the macOS. It is very reliable and fast:

Keyboard Maestro 8.2.4 on macOS 10.14.5

MACRO: Paste Versions of App and macOS (Simple Ver)

1 Like

great! ;ver; is an excellent mnemonic, thanks

1 Like