1#!/bin/sh
2echo ""
3
4USER_ID=`id -u`
5
6if [ "$USER_ID" -ne 0 ]; then
7 echo "You must be root to run the script. Use sudo $0"
8 exit
9fi
10
11## Wait for a user to log in
12CONSOLE_USER=`stat -f "%Su" /dev/console`
13
14echo "($(basename "$0")) - Checking user login session every 5 minutes..."
15while [ "$CONSOLE_USER" = "root" ] || [ "$CONSOLE_USER" = "" ]
16do
17 sleep 300
18 CONSOLE_USER=`stat -f "%Su" /dev/console`
19done
20CONSOLE_USERFULL=$(id -F "$CONSOLE_USER")
21CONSOLE_HOME=`eval echo ~${CONSOLE_USER}`
22console_user_id=`id -u ${CONSOLE_USER}`
23
24echo "($(basename "$0")) - Current logged in user is $CONSOLE_USERFULL($CONSOLE_USER, $console_user_id)"
25
26## Check the LOCKED_SCREEN_STATE every minute until it is empty which means the screensaver is not on and the screen is not locked
27LOCKED_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")
28echo "($(basename "$0")) - Checking Locked Screen State every 1 minute..."
29
30while [ -n "$LOCKED_SCREEN_STATE" ]
31do
32 sleep 60
33 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")
34done
35
36echo "($(basename "$0")) - $CONSOLE_USER logged in and the screen is not locked. Continuing..."
37
38## Display jamfHelper message until Install button is clicked
39jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
40
41windowType="utility"
42windowPosition="ur"
43title="Message Title"
44heading="Hi, $CONSOLE_USERFULL"
45description="Message"
46icon="/Applications/Self Service.app/Contents/Resources/AppIcon.icns"
47button1="Install"
48button2="More Info"
49DelayOptions="0, 900, 1800, 3600"
50
51selection=$("$jamfHelper" -windowType "$windowType" -windowPosition "$windowPosition" -title "$title" -heading "$heading" -description "$description" -icon "$icon" -button1 "$button1" -button2 "$button2" -defaultButton 1 -showDelayOptions "$DelayOptions")
52
53while [ "$selection" == "2" ]
54do
55 /bin/launchctl asuser "$console_user_id" sudo -u "$CONSOLE_USER" open "https://google.com"
56 selection=$("$jamfHelper" -windowType "$windowType" -windowPosition "$windowPosition" -title "$title" -heading "$heading" -description "$description" -icon "$icon" -button1 "$button1" -button2 "$button2" -defaultButton 1 -showDelayOptions "$DelayOptions")
57done
58
59timeChosen="${selection%?}"
60if [ -z "$timeChosen" ]; then
61 timeChosen=0
62 echo "($(basename "$0")) - Start Now was selected"
63 echo "($(basename "$0")) - Installation is starting now..."
64else
65 timeMinutes=$((timeChosen/60))
66 echo "($(basename "$0")) - $timeMinutes minutes was selected"
67 echo "($(basename "$0")) - Installation is starting in $timeMinutes minutes..."
68 sleep $timeChosen
69fi
70
71exit 0 ## Success
72exit 1 ## Failure