Use JAMFHelper to create a message with a hyperlink?

GabeShack
Valued Contributor III

Hey all,
Trying to find a way to have jamf helper post a message that has clickable links. Perhaps one of the buttons could be set to go to that link. If not I could always push a link to their desktop and just have them double click it, but I'd rather it be inline.
Gabe Shackney
Princeton Public Schools

#!/bin/bash
# Determine OS version
osvers=$(sw_vers -productVersion | awk -F. '{print $2}')

dialog="Thank you for being a part of the Mobile Access Program!

Please click on this link http://mylink.com to compete a brief technology usage survey.

Signed,
Gabe Shackney
Technology Office
Princeton Public Schools"
description=`echo "$dialog"`
button1="OK"
jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
icon="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"

if [[ ${osvers} -lt 7 ]]; then

  "$jamfHelper" -windowType utility -description "$description" -button1 "$button1" -icon "$icon"

fi

if [[ ${osvers} -ge 7 ]]; then

  jamf displayMessage -message "$dialog"

fi

exit 0
Gabe Shackney
Princeton Public Schools
2 ACCEPTED SOLUTIONS

mm2270
Legendary Contributor III

@gshackney I don't know why that would be exactly. What I posted above wasn't a complete script of course, but I assume you added the extra bits to make it into one.

I just tested the below script, both by running it locally and also calling it as root and it seemed to work for me. When I click the Open Link button it causes Safari to come to the front and opens a new tab to google.com. As you can see, I just added a few items, like a real URL to open for example and a short description text so something would be in the dialog. No issues for me. I'm on JSS 9.82 in case it matters any.

#!/bin/bash

jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"

description="This is the description"
button1="OK"
button2="Open Link"

if [[ ${osvers} -lt 7 ]]; then
    userChoice=$("$jamfHelper" -windowType utility -description "$description" -button1 "$button1" -button2 "$button2" -icon "$icon")
    if [ "$userChoice" == "2" ]; then
        open https://google.com
    else
        exit 0
    fi
fi

Edit: I just realized I didn't put in anything related to the OS version, so the comparison for $osvers is passing since there is no value for that variable in my script (null < 7). I didn't look at it clearly, but why are you checking for the OS version in your script exactly?

View solution in original post

mm2270
Legendary Contributor III

@seanjsgallagher Hey there. If I had to take a wild guess, I would say this line

open https://google.com

will now need to be run as the logged in user. In the past, not too long ago like when I posted the script above, this wasn't usually necessary, but Apple has really been tightening the screws of security in the OS a LOT over the last few versions. Especially since 10.13.x and up. So maybe using code like this will work when run via a Jamf policy? Even this isn't a guarantee now, but give it a try.

#!/bin/sh

JHELPER="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"

LOGGED_IN_USER=$(stat -f%Su /dev/console)
LOGGED_IN_UID=$(id -u "$LOGGED_IN_USER")

WELCOME=$("$JHELPER" -windowType utility -heading "Welcome to a new day." -iconSize 256 -icon /usr/local/icons/log.eps -alignDescription natural -description "Hello

Welcome" -button1 "Go" -button2 "Exit" -cancelButton "2")

if [ "$WELCOME" == "0" ]; then
      /bin/launchctl asuser "$LOGGED_IN_UID" sudo -iu "$LOGGED_IN_USER" open https://google.com
      echo "optout"
      exit 0
else
      echo "user chose No"
      exit 1
fi

If you need the URL to open in a specific browser remember you can throw in a -a Safari or -a Firefox into the open command.

View solution in original post

13 REPLIES 13

mm2270
Legendary Contributor III

Yeah, you need to make one of the buttons go to a link when clicked. There's no way to add an actual hyperlink into the text in a jamfHelper message, or a jamf displayMessage, or an Applescript dialog, or a cocoaDialog window, etc. Meaning, there are no good tools I'm aware of for messaging that can add links into them.
Apple can do it, since I've seen a number of Apple software generated dialogs have links in them, but it seems they control that and don't allow anyone to tap into that framework, probably for security reasons.

GabeShack
Valued Contributor III

Great...so just need to figure out how to make the button take me there...

Gabe Shackney
Princeton Public Schools

Gabe Shackney
Princeton Public Schools

joshuasee
Contributor III

Here was my attempt:

#!/bin/bash
#
# More flexible Casper notifications for customer by Joshua See 

note_txt="$4"; # Labeled "Notice Text" in script options
info_url="$5"; # Labeled "More Info URL" in script options
icon_url="$6"; # Labeled "Icon URL (optional)" in script options
titl_txt="$7"; # Labeled "Title (optional)" in script options

if [[ -z ${titl_txt} ]]; then 
    titl_txt="Management Notification";
    else 
    titl_txt="${titl_txt}";
fi

if [[ -n ${icon_url} ]]; then
    iconpath="/tmp/`uuidgen`";
    /usr/bin/curl -sk ${icon_url} -o ${iconpath};
    iconpath="-icon "${iconpath}"";
fi

/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType hud -windowPosition ur -alignDescription left -button2 "More Info…" -button1 OK -lockHUD -timeout 30 -defaultButton 1 ${iconpath} -title "${titl_txt}" -description "${note_txt}";

if [[ "$?" -ne 0 ]]; then
    # The launchctl call may not be required. Replace with the commented version to do without it.
    # /usr/bin/open "${info_url}";
    launchctl bsexec $(who -u | sed -n s/'.*.console.*[ 	]'//p) /usr/bin/open "${info_url}";
fi

exit 0;

mm2270
Legendary Contributor III

Generally the way to do that is to make the command that throw up the message into a variable that gets captured, since it should exit with a number indicating which button was clicked.

For example, using what you posted above (not a complete script)-

button1="OK"
button2="Open Link"

if [[ ${osvers} -lt 7 ]]; then
    userChoice=$("$jamfHelper" -windowType utility -description "$description" -button1 "$button1" -button2 "$button2" -icon "$icon")
    if [ "$userChoice" == "2" ]; then
        open http://mylink.com
    else
        exit 0
    fi
fi

Essentially, the -button2 exits with an exit code of "2" Take a look at the jamfHelper help documentation. It describes the possible button output. -button1 exits with code 0. So in the above, I'm capturing the result of the jamfHelper command in a variable called $userChoice and then checking that output. If its 2, then button 2 or "Open Link" was clicked. If its anything else, just exit.

Hope that helps.

psd_martinb
New Contributor III

I used Applescript for this purpose.
JAMF scripts allow a great deal for customizing and reusing these popups too. It even is branded with our logo (.ico file)

$6 (script parameter) is a link that is opened in the default web browser.

#!/bin/bash

MESSAGE="Hello,
$4

If you have any questions please call extension 3711 or open a ticket.

- PSD Technical Services"

BUTTONTXT="Okay"

if [ -n "$7" ]; then
    BUTTONTXT="Reboot"
fi

if [ -n "$6" ]; then
    echo "Running for user $3"
    osascript -e 'tell app "System Events" to display dialog "'"$MESSAGE"'" with title "'"$5"'" buttons {"'"$BUTTONTXT"'", "More Info"} default button 1 with icon file {"Library:Geektool:psd.icns"}
        if button returned of result = "More Info" then
            do shell script "echo Opening link"
            tell application "System Events" to open location "'"$6"'"
        else if button returned of result = "Reboot" then
            do shell script "reboot"
        end if'
else
    osascript -e 'tell app "System Events" to display dialog "'"$MESSAGE"'" with title "'"$5"'" buttons {"'"$BUTTONTXT"'"} default button 1 with icon file {"Library:Geektool:psd.icns"}
        if button returned of result = "Reboot" then
            do shell script "reboot"
        end if'
fi

When OS X updates are needed, I used this popup to alert users on login and every hour or so that they need to reboot their computer. We created and published a Google Doc that was used to convey more information.

GabeShack
Valued Contributor III

@mm2270 I tried your suggestion, but can't get the button to actually perform a command to open the url. It just closes the window.

I'll have to play with the other suggestions.

Gabe Shackney
Princeton Public Schools

Gabe Shackney
Princeton Public Schools

mm2270
Legendary Contributor III

@gshackney I don't know why that would be exactly. What I posted above wasn't a complete script of course, but I assume you added the extra bits to make it into one.

I just tested the below script, both by running it locally and also calling it as root and it seemed to work for me. When I click the Open Link button it causes Safari to come to the front and opens a new tab to google.com. As you can see, I just added a few items, like a real URL to open for example and a short description text so something would be in the dialog. No issues for me. I'm on JSS 9.82 in case it matters any.

#!/bin/bash

jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"

description="This is the description"
button1="OK"
button2="Open Link"

if [[ ${osvers} -lt 7 ]]; then
    userChoice=$("$jamfHelper" -windowType utility -description "$description" -button1 "$button1" -button2 "$button2" -icon "$icon")
    if [ "$userChoice" == "2" ]; then
        open https://google.com
    else
        exit 0
    fi
fi

Edit: I just realized I didn't put in anything related to the OS version, so the comparison for $osvers is passing since there is no value for that variable in my script (null < 7). I didn't look at it clearly, but why are you checking for the OS version in your script exactly?

B-35405
Contributor

@mm2270 thx for the code! I woke up today to a request to add a link to release notes after a software upgrade. this will work great. thx a bunch

seanjsgallagher
Contributor

@mm2270 I was trying to do something similar, posting a message and having a button to exit, and another button to open a weblink. The Apple script version would open another instance of Safari and would only work when run locally. It would not run via policy or Jamf remote. I went back in to Jamfnation and saw this thread. I have tried the script below and it works when run locally, and open the page in safari. When I run it threw Jamf remote, or via policy, the message pops up, but if I click the button to open the link Safari starts but just bounces in the dock.

In the log file it errors out

Script exit code: 0
Script result: LSOpenURLsWithRole() failed with error -600 for the URL https://google.com.
optout


!/bin/sh

WELCOME=`/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -heading "Welcome to a new day." -iconSize 256 -icon /usr/local/icons/log.eps -alignDescription natural -description "Hello

Welcome" -button1 "Go" -button2 "Exit" -cancelButton "2"`

echo "jamf helper result was $HELPER";

if [ "$WELCOME" == "0" ]; then

open https://google.com echo "optout"

exit 0 else echo "user chose No"; exit 1 fi

mm2270
Legendary Contributor III

@seanjsgallagher Hey there. If I had to take a wild guess, I would say this line

open https://google.com

will now need to be run as the logged in user. In the past, not too long ago like when I posted the script above, this wasn't usually necessary, but Apple has really been tightening the screws of security in the OS a LOT over the last few versions. Especially since 10.13.x and up. So maybe using code like this will work when run via a Jamf policy? Even this isn't a guarantee now, but give it a try.

#!/bin/sh

JHELPER="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"

LOGGED_IN_USER=$(stat -f%Su /dev/console)
LOGGED_IN_UID=$(id -u "$LOGGED_IN_USER")

WELCOME=$("$JHELPER" -windowType utility -heading "Welcome to a new day." -iconSize 256 -icon /usr/local/icons/log.eps -alignDescription natural -description "Hello

Welcome" -button1 "Go" -button2 "Exit" -cancelButton "2")

if [ "$WELCOME" == "0" ]; then
      /bin/launchctl asuser "$LOGGED_IN_UID" sudo -iu "$LOGGED_IN_USER" open https://google.com
      echo "optout"
      exit 0
else
      echo "user chose No"
      exit 1
fi

If you need the URL to open in a specific browser remember you can throw in a -a Safari or -a Firefox into the open command.

seanjsgallagher
Contributor

@mm2270 Thank you for the help this resolved the issue for me. I keep forgetting about all the security changes Apple has been making.

cbd4s
Contributor II

The only small issue is still that open link button will close the jamfhelper dialog. So when I add that button as "More Info" for user to click and find out some more details about this notification and what's going to happen, the dialog obviously disappears. As a result the user won't be clicking the actual button to "Start".

I guess one option is to use loop when "More Info" button is selected to display another jamfHelper dialog.

#!/bin/sh
echo ""

USER_ID=`id -u`

if [ "$USER_ID" -ne 0 ]; then
    echo "You must be root to run the script. Use sudo $0"
    exit
fi

## Wait for a user to log in
CONSOLE_USER=`stat -f "%Su" /dev/console`

echo "($(basename "$0")) - Checking user login session every 5 minutes..."
while [ "$CONSOLE_USER" = "root" ] || [ "$CONSOLE_USER" = "" ]
do
    sleep 300
    CONSOLE_USER=`stat -f "%Su" /dev/console`
done
CONSOLE_USERFULL=$(id -F "$CONSOLE_USER")
CONSOLE_HOME=`eval echo ~${CONSOLE_USER}`
console_user_id=`id -u ${CONSOLE_USER}`

echo "($(basename "$0")) - Current logged in user is $CONSOLE_USERFULL($CONSOLE_USER, $console_user_id)"

## Check the LOCKED_SCREEN_STATE every minute until it is empty which means the screensaver is not on and the screen is not locked
LOCKED_SCREEN_STATE=$(/bin/launchctl asuser "$console_user_id" sudo -u "$CONSOLE_USER" /usr/bin/python -c 'import sys,Quartz; d=Quartz.CGSessionCopyCurrentDictionary(); print d' | grep "CGSSessionScreenIsLocked")
echo "($(basename "$0")) - Checking Locked Screen State every 1 minute..."

while [ -n "$LOCKED_SCREEN_STATE" ]
do
    sleep 60
    LOCKED_SCREEN_STATE=$(/bin/launchctl asuser "$console_user_id" sudo -u "$CONSOLE_USER" /usr/bin/python -c 'import sys,Quartz; d=Quartz.CGSessionCopyCurrentDictionary(); print d' | grep "CGSSessionScreenIsLocked")
done

echo "($(basename "$0")) - $CONSOLE_USER logged in and the screen is not locked. Continuing..."

## Display jamfHelper message until Install button is clicked
jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"

windowType="utility"
windowPosition="ur"
title="Message Title"
heading="Hi, $CONSOLE_USERFULL"
description="Message"
icon="/Applications/Self Service.app/Contents/Resources/AppIcon.icns"
button1="Install"
button2="More Info"
DelayOptions="0, 900, 1800, 3600"

selection=$("$jamfHelper" -windowType "$windowType" -windowPosition "$windowPosition" -title "$title" -heading "$heading" -description "$description" -icon "$icon" -button1 "$button1" -button2 "$button2" -defaultButton 1 -showDelayOptions "$DelayOptions")

while [ "$selection" == "2" ]
do
    /bin/launchctl asuser "$console_user_id" sudo -u "$CONSOLE_USER" open "https://google.com"
        selection=$("$jamfHelper" -windowType "$windowType" -windowPosition "$windowPosition" -title "$title" -heading "$heading" -description "$description" -icon "$icon" -button1 "$button1" -button2 "$button2" -defaultButton 1 -showDelayOptions "$DelayOptions")
done

timeChosen="${selection%?}"
if [ -z "$timeChosen" ]; then 
    timeChosen=0
    echo "($(basename "$0")) - Start Now was selected"
    echo "($(basename "$0")) - Installation is starting now..."
else
    timeMinutes=$((timeChosen/60))
    echo "($(basename "$0")) - $timeMinutes minutes was selected"
    echo "($(basename "$0")) - Installation is starting in $timeMinutes minutes..."
    sleep $timeChosen
fi

exit 0      ## Success
exit 1      ## Failure

mhasman
Valued Contributor

I use similar solution for MS Office updates pop-up notification. "Update Now" button lunches update installation policy, "Later" opens Self Service :)