I have a script which checks computer uptime. If more than seven days it kicks off another script.
Jamf Helper showing a message with some options to restart. Here is the script:
window="utility"
title="edited the title"
heading="Please restart your computer"
description="Your computer has not been restarted in at least seven days. A more frequent restart is recommended.
Doing so optimizes the performance of your computer as well as allows us to deploy security updates or new applications to you automatically.
Please restart now."
icon="/System/Library/CoreServices/Software Update.app/Contents/Resources/SoftwareUpdate.icns"
selection=$("/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper" -windowType "$window" -title "$title" -heading "$heading" -description "$description" -icon "$icon" -button2 "Restart" -showDelayOptions "0, 60, 300, 3600, 7200" -button1 "Cancel" -cancelButton 1)
buttonClicked="${selection:$i-1}"
timeChosen="${selection%?}"
## Convert seconds to minutes for restart command
timeMinutes=$((timeChosen/60))
## Echoes for troubleshooting purposes
echo "Button clicked was: $buttonClicked"
echo "Time chosen was: $timeChosen"
echo "Time in minutes: $timeMinutes"
if [[ "$buttonClicked" == "2" ]] && [[ ! -z "$timeChosen" ]]; then
echo "Restart button was clicked. Initiating restart in $timeMinutes minutes"
shutdown -r +{$timeMinutes}
elif [[ "$buttonClicked" == "2" ]] && [[ -z "$timeChosen" ]]; then
echo "Restart button was clicked. Initiating immediate restart"
shutdown -r now
elif [ "$buttonClicked" == "1" ]; then
echo "Cancel button clicked. Exiting..."
exit 0
fi
exit
I see few different ways this fails:
Script result: 2020-04-20 13:35:57.067 jamfHelper[73095:5293090] GetInputSourceEnabledPrefs user file path = /Users/editedusername/Library/Preferences/com.apple.HIToolbox.plist
2020-04-20 13:35:57.067 jamfHelper[73095:5293090] GetInputSourceEnabledPrefs effective user id path = 0
2020-04-20 13:35:57.068 jamfHelper[73095:5293090] GetInputSourceEnabledPrefs user pref content = <CFBasicHash 0x7ff9c1457ad0 [0x7fffa0975af0]>{type = immutable dict, count = 6,
entries =>
0 : <CFString 0x7ff9c14576f0 [0x7fffa0975af0]>{contents = "AppleTimeResID"} = <CFBasicHash 0x7ff9c144ed00 [0x7fffa0975af0]>{type = immutable dict, count = 1,
entries =>
0 : smRoman = <CFNumber 0x37 [0x7fffa0975af0]>{value = +0, type = kCFNumberSInt64Type}
}
1 : <CFString 0x7fffa08a9ab8 [0x7fffa0975af0]>{contents = "AppleEnabledInputSources"} = <CFArray 0x7ff9c142ebb0 [0x7fffa0975af0]>{type = immutable, count = 2, values = (
0 : <CFBasicHash 0x7ff9c1456df0 [0x7fffa0975af0]>{type = immutable dict, count = 3,
entries =>
0 : <CFString 0x7fffa08a7218 [0x7fffa0975af0]>{contents = "InputSourceKind"} = <CFString 0x7fffa08ee098 [0x7fffa0975af0]>{contents = "Keyboard Layout"}
1 : <CFString 0x7fffa08a1d78 [0x7fffa0975af0]>{contents = "KeyboardLayout Name"} = U.S.
2 : <CFString 0x7fffa08d9b78 [0x7fffa0975af0]>{contents = "KeyboardLayout ID"} = <CFNumber 0x37 [0x7fffa0975af0]>{value = +0, type = kCFNumberSInt64Type}
}
1 : <CFBasicHash 0x7ff9c142eb70 [0x7fffa0975af0]>{type = immutable dict, count = 2,
entries =>
0 : <CFString 0x7fffa08a7218 [0x7fffa0975af0]>{contents = "InputSourceKind"} = <CFString 0x7ff9c144f400 [0x7fffa0975af0]>{contents = "Non Keyboard Input Method"}
1 : Bundle ID = <CFString 0x7ff9c144f430 [0x7fffa0975af0]>{contents = "com.apple.PressAndHold"}
}
)}
2 : <CFString 0x7fffa08c9618 [0x7fffa0975af0]>{contents = "AppleSelectedInputSources"} = <CFArray 0x7ff9c144f570 [0x7fffa0975af0]>{type = immutable, count = 1, values = (
0 : <CFBasicHash 0x7ff9c144f530 [0x7fffa0975af0]>{type = immutable dict, count = 2,
entries =>
0 : <CFString 0x7fffa08a7218 [0x7fffa0975af0]>{contents = "InputSourceKind"} = <CFString 0x7ff9c142ebf0 [0x7fffa0975af0]>{contents = "Non Keyboard Input Method"}
1 : Bundle ID = <CFString 0x7ff9c144f500 [0x7fffa0975af0]>{contents = "com.apple.PressAndHold"}
}
)}
3 : <CFString 0x7ff9c1448540 [0x7fffa0975af0]>{contents = "AppleNumberResID"} = <CFBasicHash 0x7ff9c144f5b0 [0x7fffa0975af0]>{type = immutable dict, count = 1,
entries =>
0 : smRoman = <CFNumber 0x37 [0x7fffa0975af0]>{value = +0, type = kCFNumberSInt64Type}
}
4 : <CFString 0x7ff9c1438b30 [0x7fffa0975af0]>{contents = "AppleDateResID"} = <CFBasicHash 0x7ff9c1457a90 [0x7fffa0975af0]>{type = immutable dict, count = 1,
entries =>
0 : smRoman = <CFNumber 0x37 [0x7fffa0975af0]>{value = +0, type = kCFNumberSInt64Type}
}
5 : <CFString 0x7fffa091db78 [0x7fffa0975af0]>{contents = "AppleCurrentKeyboardLayoutInputSourceID"} = <CFString 0x7fffa093bcf8 [0x7fffa0975af0]>{contents = "com.apple.keylayout.US"}
}
Button clicked was: 2
Time chosen was: 300
Time in minutes: 5
Restart button was clicked. Initiating restart in 5 minutes
shutdown: bad time format
or
Script result: Button clicked was: 2
Time chosen was: 3600
Time in minutes: 60
Restart button was clicked. Initiating restart in 60 minutes
shutdown: bad time format
Ideas?
