1#!/bin/sh
2
3## Get the logged in username
4currUser=$(/usr/bin/stat -f%Su /dev/console)
5
6## Check for a 'Services' folder in the user's home directory. Create one if necessary
7
8if [ ! -d /Users/$currUser/Library/Services ]; then
9 echo "Creating Services directory for $currUser"
10 mkdir /Users/$currUser/Library/Services
11 sudo chown -R $currUser /Users/$currUser/Library/Services
12fi
13
14## Check to see if the workflow file was installed in /tmp
15## and copy it to the current user's home Library folder
16if [ -d /private/tmp/ScreenSaver/LaunchScreenSaver.workflow ]; then
17 sudo cp -R /private/tmp/ScreenSaver/LaunchScreenSaver.workflow /Users/$currUser/Library/Services/
18 echo "Copied the workflow to $currUser's Services folder"
19 sudo chown -R $currUser /Users/$currUser/Library/Services/LaunchScreenSaver.workflow
20 echo "Set permissions on the workflow to $currUser as owner"
21 sudo chmod -R go-rwx /Users/$currUser/Library/Services/LaunchScreenSaver.workflow
22 echo "Set access on the workflow for $currUser"
23else
24 ## Exit the rest of the installation if the workflow wasn't there to copy
25 echo "The Service workflow was not found. Exiting installation..."
26 exit 1
27fi
28
29## Taking care of the shortcut for the LockScreen workflow in the current user's pbs.plist file
30if [ ! -e /Users/$currUser/Library/Preferences/pbs.plist ]; then
31 if [ -e /private/tmp/ScreenSaver/pbs.plist ]; then
32 cp /private/tmp/ScreenSaver/pbs.plist /Users/$currUser/Library/Preferences/
33 theDate=$(date +"%s")
34 /usr/bin/defaults write /Users/$currUser/Library/Preferences/pbs NSServicesUserDirectoryModDate -float $theDate
35 chown $currUser /Users/$currUser/Library/Preferences/pbs.plist
36 chmod go-rwx /Users/$currUser/Library/Preferences/pbs.plist
37 else
38 ## if we couldn't find an existing pbs.plist file for the user and the file was missing from /tmp
39 ## then we exit the rest of the installation
40 echo "The pbs.plist file was not found. Exiting..."
41 /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -title "Installation failed" -description "The Screen Saver shortcut did not install properly." -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertCautionIcon.icns" -button1 "OK" -defaultButton 1
42 exit 1
43 fi
44 else
45 ## If we found an existing plist file for the user, use PlistBuddy to add the keyboard shortcut instead
46 /usr/libexec/PlistBuddy -c 'Add :NSServicesStatus:"(null) - LaunchScreenSaver - runWorkflowAsService":key_equivalent string "@^q"' /Users/$currUser/Library/Preferences/pbs.plist
47 echo "Added LockScreen shortcut to $currUser's existing plist file"
48 ## Update the date modified string for the user's Services directory
49 theDate=$(date +"%s")
50 /usr/bin/defaults write /Users/$currUser/Library/Preferences/pbs NSServicesUserDirectoryModDate -float $theDate
51 chown $currUser /Users/$currUser/Library/Preferences/pbs.plist
52 chmod go-rwx /Users/$currUser/Library/Preferences/pbs.plist
53fi
54
55## Now we check to make sure everything is in place
56if [ -e /Users/$currUser/Library/Services/LaunchScreenSaver.workflow ]; then
57 echo "The Service was installed"
58 serviceFile="Yes"
59fi
60
61if [ -e /Users/$currUser/Library/Preferences/pbs.plist ]; then
62 echo "The shortcut file exists"
63 shortcutFile="Yes"
64fi
65
66sleep 2
67killall Finder
68
69/bin/launchctl unload /System/Library/LaunchAgents/com.apple.pbs.plist
70/bin/launchctl load /System/Library/LaunchAgents/com.apple.pbs.plist
71
72## Final clean up stage
73rm -rf /private/tmp/ScreenSaver/