We've got a GUI AppleScript which we want to run at login as the user who is logging in. It has to be saved as an .app as the AppleScript progress bar functionality does not work otherwise.
Currently we've got a policy set to trigger on login with a "Files and Processes" payload with the command open "/Library/Scripts/LongRoadInit.app"
however this seems to be somewhat unreliable as we've had a number of reports of this not getting run.
We're on OS X 10.10 Yosemite and Casper Suite 9.92.
Here's the script:
set progress description to "Long Road Mac login process"
set progress additional description to "Preparing, please wait..."
set progress total steps to -1
delay 2
set progress total steps to 7
set progress completed steps to 0
set progress additional description to "Checking if Mac is bound to Active Directory"
set checkAD to do shell script "(/usr/bin/dscl localhost -list . | grep " & (quoted form of "Active Directory") & ") || echo Not found"
if checkAD contains "Active Directory" then
-- Mac is bound to Active Directory
set thisUser to short user name of (system info)
set progress completed steps to 1
set progress additional description to "Looking up user's home directory"
set ADAccount to true
set isStudent to false
try
set smbHomeRaw to do shell script "/usr/bin/dscl localhost -read /Active\\ Directory/COLLEGE/All\\ Domains/Users/" & thisUser & " SMBHome 2>&1"
on error errMsg
set progress completed steps to -1
set progress additional description to "Not Active Directory account"
delay 2
set ADAccount to false
if thisUser is equal to "student" then
set isStudent to true
end if
end try
if ADAccount then
set studentGroups to do shell script "id " & thisUser & " | grep " & (quoted form of "All Students Security\\|Examinees")
if studentGroups as string is not equal to "" then
set isStudent to true
end if
set AppleScript's text item delimiters to " "
set the item_list to every text item of smbHomeRaw
set the new_item to text item 2 of the item_list
set AppleScript's text item delimiters to "\\"
set the new_item_list to every text item of new_item
set AppleScript's text item delimiters to "/"
set smbHome to the new_item_list as string
if smbHome does not contain thisUser then
set myErrorMessage to "Error! Home directory not found!"
display alert myErrorMessage buttons {"OK"} as critical
return
end if
delay 1
set progress completed steps to 2
set progress additional description to "Mounting user's home directory at /Users/" & thisUser & "/Documents"
do shell script "/sbin/mount -t smbfs " & smbHome & " /Users/" & thisUser & "/Documents"
if (list disks) does not contain thisUser then
set myErrorMessage to "Error! Could not mount home directory!"
display alert myErrorMessage buttons {"OK"} as critical
return
end if
end if
else
set progress completed steps to -1
set progress additional description to "Not bound to Active Directory"
delay 10
return
end if
if isStudent then
set progress completed steps to 3
set progress additional description to "Configuring Dock icons"
set dockUtilPath to "/Library/Scripts/LongRoadInit.app/Contents/Resources/Scripts/dockutil.py"
set userPath to "/Users/" & thisUser
set duNoRestart to " --no-restart"
set duAdd to " --add "
set duSectionApps to " --section apps "
set duSectionOthers to " --section others "
do shell script dockUtilPath & duNoRestart & " --remove all " & userPath
do shell script dockUtilPath & duNoRestart & duAdd & (quoted form of "/Applications/Google Chrome.app") & duSectionApps & userPath
do shell script dockUtilPath & duNoRestart & duAdd & (quoted form of "/Applications/VLC.app") & duSectionApps & userPath
do shell script dockUtilPath & duNoRestart & duAdd & (quoted form of "/Applications/Image Capture.app") & duSectionApps & userPath
do shell script dockUtilPath & duNoRestart & duAdd & (quoted form of "/Applications/Adobe Bridge CS6/Adobe Bridge CS6.app") & duSectionApps & userPath
do shell script dockUtilPath & duNoRestart & duAdd & (quoted form of "/Applications/Adobe Illustrator CS6/Adobe Illustrator.app") & duSectionApps & userPath
do shell script dockUtilPath & duNoRestart & duAdd & (quoted form of "/Applications/Adobe Photoshop CS6/Adobe Photoshop CS6.app") & duSectionApps & userPath
do shell script dockUtilPath & duNoRestart & duAdd & (quoted form of "/Applications/Adobe After Effects CS6/Adobe After Effects CS6.app") & duSectionApps & userPath
do shell script dockUtilPath & duNoRestart & duAdd & (quoted form of "/Applications/Adobe Premiere Pro CS6/Adobe Premiere Pro CS6.app") & duSectionApps & userPath
do shell script dockUtilPath & duNoRestart & duAdd & (quoted form of "/Applications/Adobe InDesign CS6/Adobe InDesign CS6.app") & duSectionApps & userPath
set scriptCommand to "if [[ -d " & (quoted form of "/Applications/Autodesk/AutoCAD 2015") & " ]];then " & dockUtilPath & duNoRestart & duAdd & (quoted form of "/Applications/Autodesk/AutoCAD 2015/AutoCad 2015.app") & duSectionApps & userPath & ";fi"
do shell script scriptCommand
do shell script dockUtilPath & duNoRestart & duAdd & (quoted form of "/Applications/Autodesk/maya2016/Maya.app") & duSectionApps & userPath
do shell script dockUtilPath & duNoRestart & duAdd & (quoted form of "/Applications/Autodesk/Mudbox2016/Mudbox.app") & duSectionApps & userPath
do shell script dockUtilPath & duNoRestart & duAdd & (quoted form of "/Applications/Microsoft Office 2011/Microsoft Word.app") & duSectionApps & userPath
do shell script dockUtilPath & duNoRestart & duAdd & (quoted form of "/Applications/Microsoft Office 2011/Microsoft Excel.app") & duSectionApps & userPath
do shell script dockUtilPath & duNoRestart & duAdd & (quoted form of "/Applications/Microsoft Office 2011/Microsoft PowerPoint.app") & duSectionApps & userPath
do shell script dockUtilPath & duNoRestart & duAdd & (quoted form of "/Applications/PCClient.app") & duSectionApps & userPath
delay 1
set progress completed steps to 4
set progress additional description to "Restarting Dock"
do shell script dockUtilPath & duAdd & (quoted form of ("/Users/" & thisUser & "/Documents")) & " --label " & (quoted form of thisUser) & duSectionOthers & userPath
delay 1
set progress completed steps to 5
set progress additional description to "Resetting wallpaper"
tell application "Finder" to set desktop picture to POSIX file "/Library/Desktop Pictures/lrsfc_lrcstudents_wallpaper_mac.jpg"
delay 1
end if
set progress completed steps to 6
set progress additional description to "Loading PaperCut client"
delay 1
tell application "System Events"
if exists file "/Applications/PCClient.app" then
do shell script "open -g /Applications/PCClient.app"
end if
end tell
delay 1
set progress completed steps to 7
set progress additional description to "Login complete, you may now start using the Mac"
delay 2