Browser Version in Self Service Policy

johnnasset
Contributor

We collect an extension attribute to display browser versions for Firefox, Chrome and Safari. I'd like to create a Self Service policy so users can determine their browser versions in a single pop-up window (either jamfhelper or Cocoa Dialog). Anybody have something like this they'd like to share?

2 ACCEPTED SOLUTIONS

mm2270
Legendary Contributor III

Something like this?

#!/bin/bash

appList="/Applications/Safari.app
/Applications/Firefox.app
/Applications/Google Chrome.app"

while read browser; do
    appVers=$(defaults read "${browser}/Contents/Info" CFBundleShortVersionString 2>/dev/null)
    if [[ ! -z "${appVers}" ]]; then
        versList+=($(echo "$(basename "$browser" .app):	${appVers}
"))
    fi
done < <(echo "${appList[@]}")

/path/to/cocoaDialog.app/Contents/MacOS/cocoaDialog msgbox 
--title "" --text "Your browser versions are:" 
--informative-text "$(echo -e "${versList[@]}" | sed 's/^ *//g')" --button1 "OK" --quiet

--Edited slightly to pipe errors to /dev/null and also added --quiet flag to suppress that the OK button was clicked.

View solution in original post

Snickasaurus
Contributor

Or this...

#!/bin/bash

# Get browser version info
theChrome=$(defaults read /Applications/Google Chrome.app/Contents/Info.plist CFBundleShortVersionString)
theFox=$(defaults read /Applications/Firefox.app/Contents/Info.plist CFBundleShortVersionString)
theSafari=$(defaults read /Applications/Safari.app/Contents/Info.plist CFBundleShortVersionString)

/usr/bin/printf "<results>
Chrome    = $theChrome
Firefox   = $theFox
Safari    = $theSafari
</results>
"

View solution in original post

19 REPLIES 19

mm2270
Legendary Contributor III

How exactly are you looking for it to be formatted or appear to the user? This seems like a fairly simple thing to accomplish.
Also, you don't need to query for the Extension Attribute to do it though, in case that's what you were thinking about, as there is always a possibility the EA values are not as up to date as pulling the actual versions from disk.

johnnasset
Contributor

A single pop-up window with something like this:

Your Firefox Version is:
Your Google Chrome Version is:
Your Safari version is:

Below is the code from the extension attribute, which I"m sure could be adapted. I'm hung up on using either jamfhelper or cocoa dialog.

if [ -d /Applications/Firefox.app ] ; then RESULT=$( sudo defaults read /Applications/Firefox.app/Contents/Info CFBundleShortVersionString ) echo "<result>$RESULT</result>"
else echo "<result>Not Installed</result>"
fi

Full disclosure: I can probably hack something together but I was asked to have this done by Friday and I'm gone tomorrow and Friday. I thought that rather than re-invent the wheel somebody around here has already done it.

mm2270
Legendary Contributor III

Something like this?

#!/bin/bash

appList="/Applications/Safari.app
/Applications/Firefox.app
/Applications/Google Chrome.app"

while read browser; do
    appVers=$(defaults read "${browser}/Contents/Info" CFBundleShortVersionString 2>/dev/null)
    if [[ ! -z "${appVers}" ]]; then
        versList+=($(echo "$(basename "$browser" .app):	${appVers}
"))
    fi
done < <(echo "${appList[@]}")

/path/to/cocoaDialog.app/Contents/MacOS/cocoaDialog msgbox 
--title "" --text "Your browser versions are:" 
--informative-text "$(echo -e "${versList[@]}" | sed 's/^ *//g')" --button1 "OK" --quiet

--Edited slightly to pipe errors to /dev/null and also added --quiet flag to suppress that the OK button was clicked.

emily
Valued Contributor III
Valued Contributor III

Ooo @mm2270 that is neat! Not getting a result for Chrome on initial testing but it would be a handy tool for our CorpIT team to use when doing troubleshooting.

Snickasaurus
Contributor

Or this...

#!/bin/bash

# Get browser version info
theChrome=$(defaults read /Applications/Google Chrome.app/Contents/Info.plist CFBundleShortVersionString)
theFox=$(defaults read /Applications/Firefox.app/Contents/Info.plist CFBundleShortVersionString)
theSafari=$(defaults read /Applications/Safari.app/Contents/Info.plist CFBundleShortVersionString)

/usr/bin/printf "<results>
Chrome    = $theChrome
Firefox   = $theFox
Safari    = $theSafari
</results>
"

johnnasset
Contributor

Okay here is what I have so far. Thanks to @mm2270 and @Snickasaurus for the suggestions:

#!/bin/bash

# Get browser version info
theChrome=$(defaults read /Applications/Google Chrome.app/Contents/Info.plist CFBundleShortVersionString)
theFox=$(defaults read /Applications/Firefox.app/Contents/Info.plist CFBundleShortVersionString)
theSafari=$(defaults read /Applications/Safari.app/Contents/Info.plist CFBundleShortVersionString)
theSilverlight=$(defaults read /Library/Internet Plug-Ins/Silverlight.plugin/Contents/Info.plist CFBundleShortVersionString)

/path/to/cocoadialog/cocoaDialog.app/Contents/MacOS/cocoaDialog msgbox
--title "" --text "Your Firefox version is: $theFox" --button1 "OK"

Is there a way to do a newline or carriage return in cocoaDialog? I'd like to include all browser versions and the version of Silverlight in a single text box.

mm2270
Legendary Contributor III

So, my reasoning behind the bash array was that as it looped through and located valid version strings it would add them into an array and then that bash array became the text to pass to the dialog.
I just tested Snickasuarus' version after deleting Firefox from my Mac and it printed this:

<results>
Chrome    = 38.0.2125.122
Firefox   = 
Safari    = 7.0.6
</results>

With mine, it prints:

**Your browser versions are:**

Safari: 7.0.6
Google Chrome:  38.0.2125.122

Note that it leaves out any mention of Firefox since its not installed. Now, I'm not saying one is necessarily better than the other, but, given that a browser may not actually be on the system when it runs, I think its better to leave out something that isn't there, personally. its up to you though.

Also, both scripts put each browser on its own line in the output/dialog.

johnnasset
Contributor

Okay, used the --informative-text option. This does what I want:

#!/bin/bash

# Get browser version info
theChrome=$(defaults read /Applications/Google Chrome.app/Contents/Info.plist $
theFox=$(defaults read /Applications/Firefox.app/Contents/Info.plist CFBundleSh$
theSafari=$(defaults read /Applications/Safari.app/Contents/Info.plist CFBundle$
theSilverlight=$(defaults read /Library/Internet Plug-Ins/Silverlight.plugin/C$

/Library/Application Support/JAMF/bin/cocoaDialog.app/Contents/MacOS/cocoaDial$
--title "Browser Versions" --informative-text "Your Firefox version is: $theFox
Your Chrome version is: $theChrome
Your Safari version is: $theSafari
Your Silverlight version is $theSilverlight" --button1 "OK" --quiet

Thanks for all of the help.

johnnasset
Contributor

Okay, spoke too soon. The above script works fine via Terminal, however, when you click OK in self service, it pops up again (and continues 5 times before finally quitting). I remember this happening before with cocoaDialog in Self Service.

Snickasaurus
Contributor

@johnnasset

You've very welcome!

@mm2270

My post was written on my iPad while in a meeting so I didn't take the time to put in any logic. Just wanted to send him something to work with.

Snickasaurus
Contributor

@johnnasset][/url

I have NO experience with cocaDialog but I hope you can find a fix soon.

Do you think it might help if perhaps your script printed the needed details to a temp file then you could call cocaDialog to read from said temp file to display whatever was in there? I will have to play around with it this weekend. Since jamfhelper is already on our machines I tend to just use it for any dialogs that I need.

mm2270
Legendary Contributor III

@Snickasaurus - fair enough! I wasn't trying to say one was right and one wrong, so sorry if it came across that way. I just wanted to make sure John understood the difference between the two. I know mine looks more complex, but there was actually a reason for that.
And kudos to you for being able to even write a script on a mobile device. Its almost impossible for me to do that!

@johnnasset - strange that its doing that! I wonder if there's just some issue with Self Service with some scripts, because there's truly no reason it should pop up 5 times, let alone 2 times. Something's definitely screwy there. I would report it to your JAMF rep. Just for kicks I'll put your final script into SS here and see if I can replicate that behavior. We're running 9.61. What version of the JSS are you on by chance?

johnnasset
Contributor

@mm2270

We are on version 9.6

emily
Valued Contributor III
Valued Contributor III

So a mixture of the scripts above would be something like this:

#!/bin/bash

# Get browser version info
theChrome=$(defaults read "/Applications/Google Chrome.app/Contents/Info" CFBundleShortVersionString)
theFox=$(defaults read "/Applications/Firefox.app/Contents/Info" CFBundleShortVersionString)
theSafari=$(defaults read "/Applications/Safari.app/Contents/Info" CFBundleShortVersionString)
Silverlight=$(defaults read "/Library/Internet Plug-ins/Silverlight.plugin/Contents/Info" CFBundleShortVersionString)


/Library/Application Support/JAMF/bin/cocoaDialog.app/Contents/MacOS/cocoaDialog msgbox 
--title "" --text "Your Browser Versions" 
--informative-text "Your Firefox version is: $theFox
Your Chrome version is: $theChrome
Your Safari version is: $theSafari
Your Silverlight version is: $Silverlight" --button1 "OK" --quiet

Tested it in SS in my environment and it worked just fine.

ETA: re-added Silverlight and fixed paths so Chrome and Silverlight reported correctly.

Snickasaurus
Contributor

@emilykausalik

After watching your video on YouTube I'm not surprised to find you lurking around a SS discussion. lol.

@mm2270

No worries man. I read it a few times and I assumed you were doing what I would do and explain to the OP the differences in the two scripts. I think the wording is what through me off. Either way +1 to you sir for showing some coca awesomeness.

emily
Valued Contributor III
Valued Contributor III

hahaha yeah… well I like following @mm2270 around on here because I learn a lot that way.

mm2270
Legendary Contributor III

hey @johnnasset - I just tested your exact posted script in my JSS through Self Service and only saw one dialog come up. So seems to work fine for me. I don't know why you're seeing more than one dialog come up. :shrugs:

If thats still happening for you, I'd let your JAMF rep know. Maybe they can help figure out why.

johnnasset
Contributor

@mm2270 Definitely not just CocoaDialog. Modified the script for jamfhelper and still got multiple pop-ups:

#!/bin/bash

# Get browser version info

theChrome=$(defaults read /Applications/Google Chrome.app/Contents/Info.plist CFBundleShortVersionString)
theFox=$(defaults read /Applications/Firefox.app/Contents/Info.plist CFBundleShortVersionString)
theSafari=$(defaults read /Applications/Safari.app/Contents/Info.plist CFBundleShortVersionString)
theSilverlight=$(defaults read /Library/Internet Plug-Ins/Silverlight.plugin/Contents/Info.plist CFBundleShortVersionString)

/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType hud -title "Browser Info" -description "Your Firefox version is: $theFox
Your Chrome version is: $theChrome
Your Safari version is: $theSafari
Your Silverlight version is: $theSilverlight" -button1 "Close" -alignDescription left

Emailing support now.

scottb
Honored Contributor

@johnnasset - FWIW, that above script (above this post) works fine in 9.32.
I served it up in SS and it only shows the dialog once, then clicks away properly.