Posted on 09-09-2012 04:16 PM
Hi all,
I have created a script to grab the logged in User's shortname and AD Home and create Symlinks on the desktop to their home and a couple of group shares.
However I have discovered that MSOffice doesn't like symlinks but Aliases work fine!
My bash scripting is weak at the best of times but my AppleScript is non-existent!
Here's what I currently have - if anybody can help me convert the 'ln' to 'make_alias' I'l buy you a beer at the JNUC :-)
#Get Current User
user=$(logname)
#GET AD Home Path and cleanup
userHome="/Volumes/"$((dscl "/Active Directory/LIMERICKSC/All Domains" -read /Users/$user SMBHome | awk '{gsub(//,"/");print}' | awk '{gsub(//," ");print$2}') | cut -d '/' -f4-)
#Just Checking...
echo $user
echo $userHome
#Symlink Home and other shares
ln -fhs "$userHome" "/Users/$user/Desktop/H_Drive"
ln -fhs "/volumes/shared" "/Users/$user/Desktop/S_Drive"
ln -fhs "/volumes/MacServer/Mac Learners/" "/Users/$user/Desktop/Mac_Learners"
Posted on 09-09-2012 09:21 PM
If your Macs are bound to a directory system such as Active Directory then the $HOME variable should do the same thing instead of parsing results from dscl.
echo $HOME
$USER is already a special variable and will give you the user's name instead of having to get it via logname.
echo $USER
But you're asking about AppleScript... Again, if your Macs are bound to a directory system such as Active Directory then this should get you their network home folder in AppleScript:
path to home folder
The syntax to create an alias would be something like:
tell application "Finder"
make alias to (path to home folder) at desktop
end tell
You can substitute "desktop" with a path to a location. Be sure you use colons instead of forward slashes as your path separators: "Macintosh HD:Users:auser:Desktop"
If they're not bound then you can still use dscl to get the user's network home folder but it will need some cleanup to convert slashes to colons and remove the "/Volume" part of the path. Post back if you need help with that.
Posted on 09-10-2012 03:58 PM
Thanks for that Moose but that is making an alias of /Users/$user, not the network home :-(
Posted on 09-11-2012 03:06 PM
OK, makes sense. That would work if you were using network home directories. Thought I'd try the easy thing first.
So, let's get the home folder path using dscl and awk within AppleScript:
set networkHomePath to do shell script "dscl "/Active Directory/TALKINGMOOSE/All Domains" -read /Users/wsmith SMBHome | awk '{print $2}'"
In our environment we're using DFS paths and Mac OS X 10.7.4, which supports DFS paths. My result is: \talkingmoose.netSTPBuisiness01users$wsmith
Unlike creating a symlink AppleScript must have access to the object before it can create an alias. That means you have to mount the network folder. We'll have to take the path we're provided and convert the backslashes to forward slashes:
set AppleScript's text item delimiters to "\" -- this is an escaped backslash
set tempList to text items of networkHomePath
set AppleScript's text item delimiters to "/"
set SMBPath to tempList as string
set AppleScript's text item delimiters to ""
My result is: //talkingmoose.net/STP/Buisiness01/users$/wsmith
We have to prefix "smb:" to the path:
set SMBPath to "smb:" & SMBPath as string
My result is: smb://talkingmoose.net/STP/Buisiness01/users$/wsmith
The AppleScript command to mount the volume is
set userHome to mount volume SMBPath
At this point, depending on your Mac OS and your network home folder setup, you may get a top level folder appearing on your desktop or you may actually get the "wsmith" folder mounted. I'm making an assumption that your Macs are bound to Active Directory and that Kerberos is working for single sign-on.
Let's see how far you get with this and we'll go from there.