Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This is an AppleScript used to look up Active Directory home directory locations. Assumptions: In order to work correctly, the script needs for the Mac to be bound to an AD domain. The AD-bound Mac also needs to be connected to the AD domain via a domain-reachable network connection or via VPN. Using the script: Launch the script and provide the…
-- Look up AD home directory script
-- Peter Bukowinski
-- Rich Trouton
-- this repeat loop prevents empty strings from being submitted
set q to 0
repeat while q is 0
set result to text returned of (display dialog "Enter the Username whose home folder you want to look up:" default answer "")
if result is not "" then
set userName to result
set q to 1
end if
end repeat
-- talk to AD, convert results to both Mac and Win paths; catch any errors and display in an error dialog
try
if (system version of (system info)) < "10.7" then
set win_path to (do shell script "/usr/bin/dscl localhost -read /Active\\ Directory/All\\ Domains/Users/" & userName & " SMBHome | awk '{print $2}'")
set mac_path to (do shell script "/usr/bin/dscl localhost -read /Active\\ Directory/All\\ Domains/Users/" & userName & " SMBHome | awk '{gsub(/\\\\/,\"/\"); print \"smb:\"$2}'")
else
set win_path to (do shell script "/usr/bin/dscl localhost -read /Active\\ Directory/DOMAIN/All\\ Domains/Users/" & userName & " SMBHome | awk '{print $2}'")
set mac_path to (do shell script "/usr/bin/dscl localhost -read /Active\\ Directory/DOMAIN/All\\ Domains/Users/" & userName & " SMBHome | awk '{gsub(/\\\\/,\"/\"); print \"smb:\"$2}'")
end if
on error errorText
display dialog "Your Mac is having trouble communicating with the Janelia Active Directory system. Please contact the help desk at 4030.
Error: " & errorText with icon stop buttons {"OK"} default button "OK"
end try
-- notify if no home is configured for the user
if win_path is "" then
set not_configured to "Home not configured in " & userName & "'s AD profile.
Ask a domain admin to fix it."
display dialog not_configured buttons "OK"
else
-- show dialog with both paths and option to copy either to clipboard
set theDialog to display dialog "Windows location: " & win_path & "
Mac location: " & mac_path buttons {"OK", "Copy Windows location", "Copy Mac location"} default button "Copy Mac location"
if button returned of theDialog is "Copy Windows location" then
set the clipboard to win_path as string
else if button returned of theDialog is "Copy Mac location" then
set the clipboard to mac_path as string
end if
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment