Skip to main content

So, here's a snippit of the AppleScript I use to mount our network home folders on login. Usually it works just fine but for a few users it doesn't work. The reason it's not working is because when dscl command reads the SMBHome field the path is on a separate line:



**set loggedInUser to do shell script "whoami"
set ADHome to do shell script "dscl /Active Directory/WMS/All Domains -read /Users/" & loggedInUser & "| grep SMBHome: | cut -c 12- | sed 's/\\///g'"



try
do shell script "mkdir /Users/Shared/networkHome/" & loggedInUser & ""



on error
--continue
end try



try
do shell script "mount_smbfs //" & loggedInUser & "@" & ADHome & " /Users/Shared/networkHome/" & loggedInUser & ""
on error
--continue
end try**



If I just type the dscl command into terminal here's what I get for the SMBHome line(s):



SMBHome:
appselementary hird gradeusername



See how they're on separate lines? So in the script when the ADHome variable is set, it's just set to the blank line. How can I grab the second line?



- jamie

pipe into a translate



[command] | tr "
" " "


Point to note, you don't need to grep, eg. (we don't use smb, so for nfs):



dscl /Active Directory/All Domains -read /Users/[username]  NFSHomeDirectory


or



dscl /Active Directory/All Domains -read /Users/[username]  dsAttrTypeNative:memberOf | tr "
" " "


Sean


Thanks for the suggestion! The translate thing seems like it might be on the right track. We use SMB for our network homes so NFSHomeDirectory doesn't seem to work, seems like I might need the grep. I'm not that skilled in scripting so I'm not totally sure how to use the translate command. Any more suggestions are greatly appreciated, I'll keep digging around.


You misunderstand. You don't need the grep, you just put in the key instead. I just used NFSHomeDirectory as an example. Replace it with whatever key you need. If the full key name is SMBHome, then use



dscl /Active Directory/All Domains -read /Users/[username] SMBHome


Not having smb homes, then I don't have this key and can't confirm that this is the full key name, but I imagine it is.


That's it! Thanks Sean!