Skip to content

Instantly share code, notes, and snippets.

@pmbuko
Created October 18, 2013 16:53
Show Gist options
  • Select an option

  • Save pmbuko/7044414 to your computer and use it in GitHub Desktop.

Select an option

Save pmbuko/7044414 to your computer and use it in GitHub Desktop.
Part of an Automator service that returns the Active Directory home path for a selected user. (http://yourmacguy.wordpress.com/2013/08/12/path-to-ad-homedir-service/)
on run {userName}
set DOMAIN to (do shell script "/usr/bin/dscl localhost -list /Active\\ Directory")
set PROTOCOL to "smb" -- or "afp"
set mac_home to (do shell script "/usr/bin/dscl localhost -read /Active\\ Directory/" & DOMAIN & "/All\\ Domains/Users/" & userName & " SMBHome | awk '{gsub(/\\\\/,\"/\"); print \"" & PROTOCOL & ":\" $2}'")
set win_home to (do shell script "/usr/bin/dscl localhost -read /Active\\ Directory/" & DOMAIN & "/All\\ Domains/Users/" & userName & " SMBHome | awk '{print $2}'")
if mac_home is "" then
display dialog "Could not find username: " & userName buttons "OK" default button "OK" with icon 0
else
set theDialog to display dialog "Mac: " & mac_home & "
Windows: " & win_home buttons {"Copy Mac", "Copy Windows", "OK"} default button "Copy Mac"
if button returned of theDialog is "Copy Mac" then
set the clipboard to mac_home as string
else if button returned of theDialog is "Copy Windows" then
set the clipboard to win_home as string
end if
end if
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment