Auto Close of JAMFHelper Message Box

DBrowning
Valued Contributor II

We are using JAMFHelper to display a message when Software Updates are ready for install. Since the user has a chose of doing them now or waiting, some users are just moving the message box out of the way. This stops the machine from checking in until the box is closed.

Is there a way to set a default response (2) and close the message box so that other policies and other check-ins happen?

here is the code i'm using currently:

if [ $Timer -gt 0 ]; then
        HELPER=`/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /System/Library/CoreServices/Installer.app/Contents/Resources/Installer.icns -heading "Software Updates are available for your Mac" -description "If you would like to install updates now, save all your work then click Yes (Then go grab a coffee or snack as you won't be able to use your computer). If you would NOT like to install updates now, click Cancel. You may choose to not install updates $Timer more time(s) before this computer will forcibly install them. A reboot will be required." -button1 "Yes" -button2 "Cancel" -cancelButton "2"`


        echo "jamf helper result was $HELPER";

        if [ "$HELPER" == "0" ]; then
            fRunUpdates
        else
            let CurrTimer=$Timer-1
            echo "$LoggedInUser clicked Cancel"
            echo "$CurrTimer" > /Library/Application Support/JAMF/.SoftwareUpdateTimer.txt
            exit 1
        fi
    fi
1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

jamfHelper has a time out flag you can throw in, called -timeout, which accepts an integer value in seconds, so add that to the end of your jamfHelper call

HELPER=`/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /System/Library/CoreServices/Installer.app/Contents/Resources/Installer.icns -heading "Software Updates are available for your Mac" -description "If you would like to install updates now, save all your work then click Yes (Then go grab a coffee or snack as you won't be able to use your computer). If you would NOT like to install updates now, click Cancel. You may choose to not install updates $Timer more time(s) before this computer will forcibly install them. A reboot will be required." -button1 "Yes" -button2 "Cancel" -cancelButton "2" -timeout 30`

Note that it returns the default button as the option chosen after timeout, so in your example it would be button1 since you designated button2 as "Cancel" I'm not sure if that's what you want, but if so then it will work as is. If not, you'd probably need to swap the buttons around and make "Cancel" the default.

View solution in original post

6 REPLIES 6

mm2270
Legendary Contributor III

jamfHelper has a time out flag you can throw in, called -timeout, which accepts an integer value in seconds, so add that to the end of your jamfHelper call

HELPER=`/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /System/Library/CoreServices/Installer.app/Contents/Resources/Installer.icns -heading "Software Updates are available for your Mac" -description "If you would like to install updates now, save all your work then click Yes (Then go grab a coffee or snack as you won't be able to use your computer). If you would NOT like to install updates now, click Cancel. You may choose to not install updates $Timer more time(s) before this computer will forcibly install them. A reboot will be required." -button1 "Yes" -button2 "Cancel" -cancelButton "2" -timeout 30`

Note that it returns the default button as the option chosen after timeout, so in your example it would be button1 since you designated button2 as "Cancel" I'm not sure if that's what you want, but if so then it will work as is. If not, you'd probably need to swap the buttons around and make "Cancel" the default.

thoule
Valued Contributor II

Put the timeout in the Jamfhelper line.

#!/bin/sh
jamfhelper -help

-timeout int
        Causes the window to timeout after the specified amount of seconds
        Note: The timeout will cause the default button, button 1 or button 2 to be selected (in that order)

DBrowning
Valued Contributor II

Thanks @mm2270 and @thoule

I had been looking for a Man file on jamfhelper. didn't realized i had to run it as a script.

mm2270
Legendary Contributor III

It doesn't need to be run "as a script" but it does not have a manpage. It has a help flag. I think @thoule was just showing that as an example. You can access the full jamfHelper help with the following in Terminal:

/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -help

Note: In older versions of the JSS the above needed to be run as root since the "bin" directory was locked from non root shells, but that changed around the time the Management Action.app was introduced since if that directory was locked it probably wouldn't have been able to send up Notification Center messages.

DBrowning
Valued Contributor II

of course now it works. before i was getting a pretty generic help page. Thanks again!

el2493
Contributor III

Hey, I know this is an old post but it helped me out!

One question: I'm using this to give a message that a computer is going to restart. I want it to either timeout after 5 minutes and then restart, or if a user clicks a "Restart Now" button I want it to restart immediately.

My script (the relevant part) is:

#!/bin/sh

#message information
msgprompthead="Personal Logins are not Permitted on this Computer"
msglogout="This computer will restart in 5 minutes and login to the public lab account.

Please save any open files to a USB drive as files stored on this profile will be deleted when the computer restarts."

dialogicon="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/Resources/Restart.png"
jamfhelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"

restartprompt=$("${jamfhelper}" -windowType utility -heading "${msgprompthead}" -alignHeading center -description "${msglogout}" -icon "${dialogicon}" -button1 "Restart Now"  -defaultButton 1 -timeout 300)
sudo osascript -e 'tell app "System Events" to  «event aevtrlgo»'
exit 0

My thought was that if the user clicks "Restart Now" it would close out of the jamfhelper window and then move on to the next line (to restart), or if the window timed out it would do the same thing (move on the the next line and restart). However, that doesn't seem to be the case. The window shows and times out appropriately, but the restart doesn't happen (whether or not I click "Restart Now"). Do I need to add something like:

if [ "$restartprompt" == "0" ]; then
            sudo osascript -e 'tell app "System Events" to  «event aevtrlgo»'
            exit 0
else
            sudo osascript -e 'tell app "System Events" to  «event aevtrlgo»'
            exit 0
fi

?