Jamf helper Countdown Issue

kamahmed
New Contributor II

I am for one reason or another still unable to get the countdown time to appear, even though i'm sure I have set it.

Any pointers where I might have gone wrong

#!/bin/bash
####################################################################################################
#
# Copyright (c) 2013, JAMF Software, LLC.  All rights reserved.
#
#       This script was written by the JAMF Software Profesional Services Team
#
#       THIS SOFTWARE IS PROVIDED BY JAMF SOFTWARE, LLC "AS IS" AND ANY
#       EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
#       WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#       DISCLAIMED. IN NO EVENT SHALL JAMF SOFTWARE, LLC BE LIABLE FOR ANY
#       DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
#       (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#       LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#       ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#       (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
#       SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#####################################################################################################
#
# SUPPORT FOR THIS PROGRAM
#
#       This program is distributed "as is" by JAMF Software, Professional Services Team. For more
#       information or support for this script, please contact your JAMF Software Account Manager.
#
#####################################################################################################
#
# ABOUT THIS PROGRAM
#
# NAME
#   jamfHelperByPolicy.sh
#
# SYNOPSIS - How to use
#   Run via a policy to populate JAMF Helper with values to present messages to the user.
#
# DESCRIPTION
#
#   Populate script parameters to match the variables below.
#   Pass in values into these parameters during a policy.
#
####################################################################################################
#
# HISTORY
#
#   Version: 1.0
#
#   - Created by Douglas Worley, Professional Services Engineer, JAMF Software on May 10, 2013
#
####################################################################################################
# The recursively named JAMF Helper help file is accessible at:
# /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -help

windowType=""         #   [hud | utility | fs]
windowPosition="" #   [ul | ll | ur | lr]
title=""          #   "string"
heading=""            #   "string"
description=""        #   "string"
icon=""               #   path
iconSize=""           #   pixels
timeout=""            #   seconds


[ "$4" != "" ] && [ "$windowType" == "" ] && windowType=$4
[ "$5" != "" ] && [ "$windowPosition" == "" ] && windowPosition=$5
[ "$6" != "" ] && [ "$title" == "" ] && title=$6
[ "$7" != "" ] && [ "$heading" == "" ] && heading=$7
[ "$8" != "" ] && [ "$description" == "" ] && description=$8
[ "$9" != "" ] && [ "$icon" == "" ] && icon=$9
[ "$10" != "" ] && [ "$iconSize" == "" ] && iconSize=$10
[ "$11" != "" ] && [ "$timeout" == "" ] && timeout=$11

function setSnooze ()
{

## Get the time right now in Unix seconds
timeNow=$(date +"%s")
## Calculate the time for the next available display of the prompt (adds the time now and time chosen together in seconds)
timeNextRun=$((timeNow+SnoozeVal))

## Create or update a plist value containing the above next time to run value
/usr/bin/defaults write /Library/Preferences/com.acme.policy_001.snooze.plist DelayUntil -int $timeNextRun

exit 0

}

function showPrompt ()
{

## Prompt, and capture the output
HELPER=$("/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfhelper" -windowType "$windowType" -windowPosition "$windowPosition" -title "$title" -heading "$heading" -description "$description"  -icon "$icon" -iconSize "$iconSize" -button1 Install Now” -button2 Snooze -defaultButton 2 -cancelButton "2" -countdown "$timeout" -timeout "$timeout" -showDelayOptions "900, 1800, 3600, 7200, 14400")

echo "jamf helper result was $HELPER"

## Dissect the response to get just the button clicked and the value selected from the drop down menu
ButtonClicked="${HELPER: -1}"
SnoozeVal="${HELPER%?}"

echo "$ButtonClicked"
echo "$SnoozeVal"

if [ "$ButtonClicked" == "1" ]; then
    echo "User chose Install"
    /usr/bin/jamf policy -trigger office2019
    exit 0
elif [ "$ButtonClicked" == "2" ]; then
    echo "User chose Snooze"
    setSnooze
fi

}

## Get a value (if possible) from a plist of the next valid time we can prompt the user
SnoozeValueSet=$(/usr/bin/defaults read /Library/Preferences/com.acme.policy_001.snooze.plist DelayUntil 2>/dev/null)

## If we got something from the plist...
if [ -n "$SnoozeValueSet" ]; then
    ## See what time it is now, and compare it to the value in the plist.
    ## If the time now is greater or equal to the value in the plist, enough time has elapsed, so...
    timeNow=$(date +"%s")
    if [[ "$timeNow" -ge "$SnoozeValueSet" ]]; then
        ## Display the prompt to the user again
        showPrompt
    else
        ## If the time now is less than the value in the plist, exit
        echo "Not enough time has elapsed. Exiting..."
        exit 0
    fi
else
    ## If no value was in the plist or the plist wasn't there, assume it is the first run of the script and prompt them
    showPrompt
fi
6 REPLIES 6

alexjdale
Valued Contributor III

Try removing the "$timeout" after the -countdown argument. That is just a flag telling jamfhelper to show a countdown, but the -timeout arg is where the timer is actually set. The -countdown arg doesn't take a parameter.

kamahmed
New Contributor II

@alexjdale thanks for that suggestion still the countdown does not appear, this is very odd

tlarkin
Honored Contributor

I don't have a bash example handy but I am using this in Python (which is subprocess commands anyway) and the timer works for me

def force_prompt(prompt):
    """simple jamf helper dialog box"""
    # yeti bot icon!!!!
    icon = "/Library/Application Support/JAMF/snowflake/yeti_yikes.png"
    # test to see what icons are available on the file system
    if not os.path.exists(icon):
        # default fail over icon in case our custom one does not exist
        icon = "/System/Library/CoreServices/Problem Reporter.app/Contents/Resources/ProblemReporter.icns"
        # build the jamf helper unix command in a list
    cmd = [
        "/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper",
        "-windowType",
        "hud",
        "-title",
        "Run Software Updates",
        "-description",
        prompt,
        "-alignDescription",
        "natural",
        "-icon",
        icon,
        "-iconSize",
        "300",
        "-button1",
        "Restart Now",
        "-defaultbutton",
        "1",
        "-timeout",
        "7200",
        "-countdown",
        "-alignCountdown",
        "center",
        "-lockHUD"
    ]
    # call the command via subprocess
    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    # get stdout and stderr
    out, err = proc.communicate()
    # check for exit status for button clicked, 0 = OK 2 = Cancel
    if proc.returncode == 0:
        # user clicked OK
        return True

sdagley
Honored Contributor II

@kamahmed Any positional parameter higher than 9 must use braces (e.g. use ${10} instead of $10) so parameters 10 and 11 are not being recognized by your current script. And what @alexjdale said regarding the -countdown argument not taking any parameters.

kamahmed
New Contributor II

Hi @sdagley that did the trick, only issue now is that when selecting snooze the countdown resets the timer when it re-appears.
Also looking at if timeout has expired to force the custom trigger install

sdagley
Honored Contributor II

@kamahmed The countdown timeout should be the same every time that prompt appears (that's how the script is written). If you want the install policy to run at the end of the countdown, it looks like you can just change -defaultButton 2 in the call to jamfhelper to -defaultButton 1