User Interaction Custom Icon

AdamCraig
Contributor III

3d67480804e1495d817b2fcf2d039463

We set up policy using the user interaction tool allowing the user to defer the policy. Is there a way we can brand the notification with our icon?

Is it possible to include weblinks in the notification as well?

I poked around Jamf and Jamf Nation and wasn't able to figure this out. Thanks,

6 REPLIES 6

marklamont
Contributor III

nope, but feel free to upvote this and raise with your jamf buddy. I have because it's a poor implementation of branding that only one bit gets done.

aprild
New Contributor II

I have upvoted the link but wanted to say that I would like the ability to use the icon associated with the policy for this pop-up. Thanks!

mickgrant
Contributor

its not Jamf native yet but you should check out - Jamf-Interaction-Toolkit
it will automatically use your self service branding, you can also change it to something else manually

dtmille2
Contributor II

Upvoted! Adding a logo to the user interaction section of a Policies is essential! Let's get the ball rolling with this Jamf!

athomson
New Contributor III

This is a close approximation. --Andrew

#!/bin/bash
# set -x

#    This script was written to run from the JSS to provide a universal
#    front end for application updates. 

#    Author:        Andrew Thomson
#    Date:          2019-06-19, updated 2021-03-03, 2021-05
#    GhitHub:    https://github.com/thomsontown

#    PARAMETER 4: Name of application to be updated.
#    PARAMETER 5: An array of process names to kill before update.
#    PARAMETER 6: The custom trigger name that corresponds to the update policy.
#    PARAMETER 7: The path to the icon associated with the application.


IFS=$'
'


function getSecondsUntilTime() {

    local TIME="$1"

    if [[ ! $TIME =~ ^[0-9][0-9]:[0-9][0-9]$ ]]; then 
        echo "ERROR: The time submitted to calculate is missing or improperly formatted." >&2 
        return $LINENO
    fi

    local TARGET_EPOCH=$(/bin/date -jf "%D %H:%M" "$(/bin/date +%D) $TIME" +%s)
    local CURRENT_EPOCH=$(/bin/date +%s)
    local SECONDS=$(($TARGET_EPOCH-$CURRENT_EPOCH))
    echo "$SECONDS"
}


function jamfHelper () {

    COMMAND=""/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper""
    COUNT=$#

    for ((INDEX=1;INDEX<=$COUNT;INDEX++)); do 
        case "$INDEX" in 
            1)  if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -windowType $1"            ;fi ;;
            2)  if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -windowPosition $1"        ;fi ;;  
            3)  if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -title "$1""             ;fi ;;
            4)  if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -heading "$1""           ;fi ;;
            5)  if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -description "$1""       ;fi ;;
            6)  if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -icon "$1""              ;fi ;;
            7)  if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -button1 $1"               ;fi ;;
            8)  if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -button2 $1"               ;fi ;;
            9)  if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -defaultButton $1"         ;fi ;;
            10) if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -cancelButton $1"          ;fi ;;
            11) if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -showDelayOptions "$1""  ;fi ;;
            12) if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -alignDescription $1"      ;fi ;;
            13) if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -alignHeading  $1"         ;fi ;;
            14) if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -alignCountdown $1"        ;fi ;;
            15) if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -timeout $1"               ;fi ;;
            16) if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -countdown"                ;fi ;;
            17) if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -iconSize $1"              ;fi ;;
            18) if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -lockHUD"                  ;fi ;;
            19) if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -startlaunchd"             ;fi ;;
            19) if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -kill"                     ;fi ;;
            20) if [[ ${#1} -ne 0 ]]; then COMMAND="$COMMAND -fullScreenIcon"           ;fi 
        esac    
        shift
    done

    (/bin/bash -c "${COMMAND}") & HELPER_PID=$!
}


function isRoot () {

    #   verify script run as root
    if [[ $UID -ne 0 ]]; then

        echo "ERROR: Script must run with root privileges." >&2
        echo -e "\tUSAGE: sudo "$0"" >&2
        return $LINENO
    else
        return 0
    fi
}


function main () {

    NAME="$1"
    PROCESS="$2"
    TRIGGER="$3"
    ICON="$4"
    TITLE="Application Update"
    HEADING="Application Update: $NAME"
    DEFER_DOM="com.mycompany.deferrals"
    MAX_TIME="19:00" 
    DELAY_OPTIONS="0"

    #   for testing
    # NAME="Firefox"
    # HEADING="Application Update: $NAME"
    # PROCESS="Firefox"
    # TRIGGER="trg_firefox"
    # ICON="/Applications/Firefox.app/Contents/Resources/firefox.icns"

    #  verify root
    if ! isRoot; then 
        exit $LINENO
    fi

    #   verify passed variables
    echo -e "NAME: $NAME
PROCESS: $PROCESS
TRIGGER: $TRIGGER
ICON: $ICON"
    if [ -z "$NAME" ] || [ -z "$PROCESS" ] || [ -z "$TRIGGER" ] || [ -z "$ICON" ]; then 
        echo "ERROR: Missing parameter(s)." >&2
        exit $LINENO
    fi    

    #   if no user logged in then apply update
    if ! /usr/bin/pgrep -i "loginwindow" &> /dev/null; then 
        echo "Running Update $NAME --> $(/bin/date +"%x %r")"
        /usr/local/bin/jamf policy -event $TRIGGER
        /usr/bin/defaults delete $DEFER_DOM "$NAME" &> /dev/null
        exit 0
    fi

    #   if process not running then apply update
    if ! /usr/bin/pgrep -i "$PROCESS" &> /dev/null; then
        echo "Running Update $NAME --> $(/bin/date +"%x %r")"
        /usr/local/bin/jamf policy -event $TRIGGER
        /usr/bin/defaults delete $DEFER_DOM "$NAME" &> /dev/null
        exit 0
    fi   

    #   verify jamfHelper binary
    if [ ! -x "/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper" ]; then
        echo "ERROR: Required binary not found [jamfHelper]." >&2
        exit $LINENO
    fi

    #   verify icon
    if [ ! -f "$ICON" ]; then
        echo "ERROR: Specified icon not found [$ICON]. Using default." >&2
        ICON="/Library/Verisign/vrsn-blue-flat.png"
    fi

    #   read deferral time
    DEFERRAL_TIME=$(/usr/bin/defaults read $DEFER_DOM $NAME 2> /dev/null)

    #   get current time in epoch format
    CURRENT_TIME=$(/bin/date +%s)

    #   build delay options as a string        
    DELAY_OPTION_MAX=$(getSecondsUntilTime "$MAX_TIME")
    if [ "3600"  -lt "$DELAY_OPTION_MAX" ]; then DELAY_OPTIONS+=", 3600"  ; fi
    if [ "7200"  -lt "$DELAY_OPTION_MAX" ]; then DELAY_OPTIONS+=", 7200"  ; fi
    if [ "10800" -lt "$DELAY_OPTION_MAX" ]; then DELAY_OPTIONS+=", 10800" ; fi
    if [ "14400" -lt "$DELAY_OPTION_MAX" ]; then DELAY_OPTIONS+=", 14400" ; fi  
    DELAY_OPTIONS+=", $DELAY_OPTION_MAX"     

    #   if deferral time is set but not surpassed, exit until next policy time
    if [ -n "$DEFERRAL_TIME" ] && [ "$CURRENT_TIME" -lt "$DEFERRAL_TIME" ]; then 
        echo "Pending Update: $NAME --> $(/bin/date -jf %s "$DEFERRAL_TIME" +"%x %r")"
        exit 0
    fi

    #   prompt for update or deferal time
    if [ -n "$DEFERRAL_TIME" ] && [ "$CURRENT_TIME" -ge "$DEFERRAL_TIME" ]; then 
        RC=$(jamfHelper "utility" "$WINDOW_POSITION" "$TITLE" "$HEADING" "An update is required for $NAME. Be sure to save your data for $NAME, then click the OK button below. 

If you require assistance, please contact the Help Desk at 800-000-0000." "$ICON" "OK" "$BUTTON_2" "1" "$CANCEL_BUTTON" "$SHOW_DELAY_OPTIONS" "$ALIGN_DESCRIPTION" "$ALIGN_HEADING" "center" "900" "true" "$ICON_SIZE")
    else 
        RC=$(jamfHelper "utility" "$WINDOW_POSITION" "$TITLE" "$HEADING" "An update is required for $NAME. The default option is 'Start now', but you can defer the update by selecting an alternate time from the list below. The last option will always calculate to 7pm local time. Be sure to save your data for $NAME, then click the OK button below.

If you prefer to avoid further prompting, you can apply the update directly from Self Service before the deferral time expires. 

If you require assistance, please contact the Help Desk at 800-000-0000." "$ICON" "OK" "$BUTTON_2" "1" "$CANCEL_BUTTON" "$DELAY_OPTIONS" "$ALIGN_DESCRIPTION" "$ALIGN_HEADING" "center" "900" "true" "$ICON_SIZE")
    fi

    #   launch update or write selected deferral time to plist
    case $RC in
            0) true ;;
            1) true ;;
        36001) /usr/bin/defaults write $DEFER_DOM $NAME "$(/bin/date -v+1H -jf %s "$CURRENT_TIME" "+%s")"; exit 0 ;;              # 1 Hour
        72001) /usr/bin/defaults write $DEFER_DOM $NAME "$(/bin/date -v+2H -jf %s "$CURRENT_TIME" "+%s")"; exit 0 ;;              # 2 Hours
       108001) /usr/bin/defaults write $DEFER_DOM $NAME "$(/bin/date -v+3H -jf %s "$CURRENT_TIME" "+%s")"; exit 0 ;;              # 3 Hours
       144001) /usr/bin/defaults write $DEFER_DOM $NAME "$(/bin/date -v+4H -jf %s "$CURRENT_TIME" "+%s")"; exit 0 ;;              # 4 Hours
            *) /usr/bin/defaults write $DEFER_DOM $NAME "$(/bin/date -jf "%D %T" "$(/bin/date +%D) $MAX_TIME:00" +%s)"; exit 0 ;; # Always 7:00pm
    esac

    #   kill process 
    /usr/bin/pkill -if "$PROCESS" 

    #   apply update
    echo "Running Update $NAME --> $(/bin/date +"%x %r")"
    /usr/local/bin/jamf policy -event $TRIGGER &
    UPDATE_PID="$!"

    #   launch update dialog to notify update in progress
    jamfHelper "utility" "$WINDOW_POSITION" "$TITLE" "" "Please wait while $NAME updates are applied, followed by a required system inventory." "$ICON" "$BUTTON_1" "$BUTTON_2" "$DEFAULT_BUTTON" "$CANCEL_BUTTON" "$SHOW_DELAY_OPTIONS" "$ALIGN_DESCRIPTION" "$ALIGN_HEADING" "$ALIGN_COUNTDOWN" "$TIMEOUT" "$COUNTDOWN" "$ICON_SIZE" "LOCKHUD" "$START_LAUNCHD" "$KILL" "$FULL_SCREEN_ICON" &

    #   monitor software update pid
    while /bin/kill -0 $UPDATE_PID &> /dev/null; do
        /bin/sleep 3
    done

    #   kill update dialog once software update pid disappears
    /usr/bin/pkill jamfHelper

    #   reset deferral count
    if [ -n "$DEFERRAL_TIME" ];then 
        /usr/bin/defaults delete $DEFER_DOM "$NAME" &> /dev/null
    else 
        exit 0
    fi    
}


if [[ "$BASH_SOURCE" == "$0" ]]; then
    shift 3
    main $@
    exit
fi

ChrisTech
Contributor

I set up the script. It works if the app process is not there, or is there and I don't choose a delay. Am I missing something here?