Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Need help with logon Script

Hi I'm trying to create a script to mount a NAS storage drive, and create an alias to the users space on the NSA drive on their desktop. We are a school who use both Macs and PC. I am planning on creating a separate script for staff and students, this is the staff script.


Note: The user desktop is stored on the Windows server.

Note2: I'm very new to applescript


1 set username to (do shell script "whoami")

2 set StorageDrive to ("afp://10.250.9.55/StaffHomeFolders")

3 set HomeDrive to ("smb://Staff/Users/" & username as text)

4

5 tell application "Finder"

6 mount volume StorageDrive

7 mount volume HomeDrive

8 make to "StaffHomeFolders:" & username as text at (username as text) & ":Desktop" new alias file

9 end tell


Note3: If I change line 8 to: {make to "StaffHomeFolders:Tom" at (username as text) & ":Desktop" new alias file} the script will work.


Error: Finder got an error: Can't make \"StaffHomeFolders:tom\" into type item. number -1700 from "StaffHomeFolders:tom" to item


Any help will be welcomed

iMac, Mac OS X (10.6.8), AppleScript

Posted on Oct 2, 2012 4:44 AM

Reply
Question marked as Best reply

Posted on Oct 2, 2012 9:26 AM

I have admit to being confused as to your goals here, or why you're doing it via a login script.


By far the easiest way to have a volume mount when you login is to add it to your account's Login Items.


Additionally, by default, mounted volumes appear on your desktop anyway, so it's not clear why you're creating aliases (which, I assume, is what your script is trying to do since 'make to...' makes no sense in AppleScript).


Even if you have mounted volumes turned off in Finder preferences, you can create an alias once and it will be persistent (including automatically remounting the remote volume as needed), so it would be a mistake to create the alias every time the user logs in - or, at the very least, superfluous. You should probably check to see if the alias already exists before trying to create a new one.

12 replies
Question marked as Best reply

Oct 2, 2012 9:26 AM in response to ThomasFrom CF

I have admit to being confused as to your goals here, or why you're doing it via a login script.


By far the easiest way to have a volume mount when you login is to add it to your account's Login Items.


Additionally, by default, mounted volumes appear on your desktop anyway, so it's not clear why you're creating aliases (which, I assume, is what your script is trying to do since 'make to...' makes no sense in AppleScript).


Even if you have mounted volumes turned off in Finder preferences, you can create an alias once and it will be persistent (including automatically remounting the remote volume as needed), so it would be a mistake to create the alias every time the user logs in - or, at the very least, superfluous. You should probably check to see if the alias already exists before trying to create a new one.

Oct 3, 2012 2:11 AM in response to Camelot

Hi we do have Workgroup Manager, and I had a look into the Login Items to try and map them there, but I can't really get my head around it. We have 120 Staff and 1400 pupils, pupils are divided into 7 different year groups. The structure of the NAS is as follows:


Route - StaffHomeFolders (shared file) - Username


Route - PupilHomeFolders (shared file) - Year Group - Username


I can set a single volume to mount for every member of a group i.e Public for Year 7 Pupils. But I can't find a way for them to pickup a unique folder and mount that. Every time I click to add a login item it wants me to browse and select it? That's why I'm trying the Login Script.


The reason I'm trying to place an alias on the user desktop is to diffarenshiate it from the Network Home Folder each user maps by default. I think the Macs pulls this from our Active Directory automatically. The Network home file is also named the same as the user name.


This was all done every well and easily on our windows side. I simply set it to map a V:\ drive to //10.250.9.55/StaffHomeFolders/%username% We are using this as a sort of second user area for large video files.


Thanks for the reply if you can think of anyway I can accomplish this without using a logon script or using a different script, I would be happy to entertain any suggestions.

Feb 11, 2014 4:31 AM in response to ThomasFrom CF

Hi, Bit of a blast from the past but did you ever figure out a way of doing this?


The following osascript will create the alias as long as the drive has already been mounted: -

osascript -e 'tell application "Finder" to make alias file to alias "Volumes:Students:YearGroup:Username" at desktop'


I'm trying to figure out how to automatically insert the YearGroup variable, I can pull the UserName from their login. It also needs to check that the alias doesn't already exist otherwise I expect they're going to get a new alias created everytime they log in.

Feb 11, 2014 9:16 AM in response to PVCSBlakey

Errr... I'm not sure whether your question was answered. I'll assume that you know how to get both the username and year group and have modified the script accordingly. If that's not true and you still need help, you'll need to be much more specific about how you get the username and how you transform it into the year group thing. What you said above doesn't help with that one bit.

Feb 11, 2014 10:40 AM in response to PVCSBlakey

For ourselves the year group is a partial match against the username so if their username is '7035' their year group is '7000'


Are you saying the userids are numeric? Are you saying that the user has an id of 7035? ugly. Are you saying the user names are 4 didgits long? You take the first digit and add three zeroes?


btw:

this is a bash script:


osascript -e 'set group to "xxx"

set yg to ((year of (current date)) as text) & group

tell application "Finder"

make new alias file at desktop to folder username of folder yg of disk "Students"

end tell'


# make script executable. use command in terminal.

chmod 744 pickremote.sh


hence for script pickremote.sh:

#!/bin/bash

osascript -e 'set group to "xxx"

set yg to ((year of (current date)) as text) & group

tell application "Finder"

make new alias file at desktop to folder username of folder yg of disk "Students"

end tell'

Feb 13, 2014 4:42 AM in response to rccharles

Yes the userids are numeric but not completely they're actually in the format pv7035, pv7036, etc. These are userids for students and with over a thousand students, many with similar or identical names (we've even had a few with the same name and date of birth), and 210 new students every year we use their exam number for their userid as it is unique, short and easily remembered.


So userid pv7035's network drive resides within the /Volumes/Students/7000 folder, userid pv6099's network drive resides within the /Volumes/Students/6000 folder, etc.


I'd like a bash script that runs when they log in (I'll stick a loginagent.plist, to trigger the script, in /Library/LaunchAgents) that creates an alias on their desktop to their personal network drive with an IF statement to check whether an alias already exists (in which case it would skip creating one).


For example: -

When userid pv7035 logs in the equivelant of this runs

osascript -e 'tell application "Finder" to make alias file to alias "Volumes:Students:7000:pv7035" at desktop'


When userid pv6099 logs in the equivelant of this runs

osascript -e 'tell application "Finder" to make alias file to alias "Volumes:Students:6000:pv6099" at desktop'


We have students' network drives mounting on their desktop currently but this is treated as their network home (e.g. /Users/pv7035/NetworkHome/) so when we are saving anything in there that is network path aware (e.g. HTML files within Dreamweaver) it causes us problems with things like previewing them, etc. When previewing within Dreamweaver it will direct Safari/Firefox/etc. to look for the document at file:///pv7035/index.html so nothing displays because the file actually resides at file:///Volumes/Students/7000/pv7035/index,html, saving the file via an alias to /Volumes/Students/7000/pv7035 results in preview working correctly.


We've also experienced a number of problems with iMovie projects saved on the network (projects opening up empty, etc.) which may or may not be related to how OS:X is handling their network share and the current way the drive is mounted.

Feb 16, 2014 12:22 PM in response to PVCSBlakey

I used the finder to connect to a samba share. I used the finder to create an alias.


I double clicked on the alias to get the list of file on the remote server. I double clicked on an html file.


I get this as the address in TenFourFox ( a port of FireFox. )


file:///Volumes/GROUPF20%3bLOCALHOST/%20aStandardFixes.html


I get this in safari too.

file:///Volumes/GROUPF20%3BLOCALHOST/%20aStandardFixes.html


How are the files shared? I assume they are windows shares. samba.


Have you thought of trying the Unix ln command instead of an alias?


---------------------------------------



Unix command ln -- The Unix make link command. I have a copy of virtual PC. It insists on using a folder in my documents folder for saving all of the virtual machine information. This folder is rather large. I used the terminal command ln to move the folder to my external hard drive. Virtual PC had no problem with this move. I do not think that Mac applications notice the ln redirects.

You can use the Unix command ln to redirect a reference to folder on your small partition to a folder on your larger partition. You need to be careful when you pick the folder. You best avoid any system folder, those folders needed at startup. You could pick some user data folder. Home folders, that is folders in /Users, are a good choice. Please try this when you have a full backup.

mac harddrive > Applications > Utilities > Terminal
man ln
ln -s target source


example:
let's make like my Christmas card folder is on my desktop and make like the names is cards.
mac $ ls /Volumes
GREEN/ Macintosh-HD@
mac $ ls /Volumes/GREEN/Christmas\ Cards/
10 - NeoOffice Writer.pdf* christmasLabels.odt*
AddressList.ods* env - NeoOffice Writer.pdf*
ChristmasAddressList.xls* env.odt*
ChristmasAddressList0.odb* getLabels.odt*
al.odb*
mac $ cd ~/Desktop/
mac $ pwd
/Users/mac/Desktop
mac $ ln -s /Volumes/GREEN/Christmas\ Cards/ cards
mac $ cd cards/
mac $ pwd
/Users/mac/Desktop/cards
mac $ ls
10 - NeoOffice Writer.pdf* christmasLabels.odt*
AddressList.ods* env - NeoOffice Writer.pdf*
ChristmasAddressList.xls* env.odt*
ChristmasAddressList0.odb* getLabels.odt*
al.odb*
mac $

An alternative way would be to install SymbolicLinker. SymbolicLinker is a tiny contextual menu plugin that, once installed, allows any user to create symbolic links to files inside the Finder.

http://www.macupdate.com/info.php/id/10433/
How to redirect your iPhoto and ITunes files to an external harddrive:
http://discussions.apple.com/thread.jspa?messageID=6058202#6058202

Robert PS. Let me know how this goes. I'll see if I can find some way of recreating the problem.

Feb 20, 2014 7:22 AM in response to rccharles

Hi Robert,


Thanks for your help with this - the way the aliases operate isn't the problem it is how to automate the alias creation for each user upon log in that I'm scratching my head over. I need some way of passing the user's network drive path variable in to the osascript as per the examples below: -


For example: -

When userid pv7035 logs in the equivelant of this runs

osascript -e 'tell application "Finder" to make alias file to alias "Volumes:Students:7000:pv7035" at desktop'


When userid pv6099 logs in the equivelant of this runs

osascript -e 'tell application "Finder" to make alias file to alias "Volumes:Students:6000:pv6099" at desktop'


When userid pv1264 logs in the equivelant of this runs

osascript -e 'tell application "Finder" to make alias file to alias "Volumes:Students:1000:pv1264" at desktop'


A check for an existing alias (IF statement) will also be required to avoid a duplicate alias being created everytime they log in.

Feb 21, 2014 11:29 AM in response to PVCSBlakey

Since you are invoking the script from bash, you can imbed the data in the Applescript


#!/bin/bash

userid=$(whoami)

# pull out the "7" then append

userGrade=${userid:2:1}"000"

# Variable are imbed within double quote strings.

# put \ before " to escape as needed.


osascript -e "tell application \"Finder\" to make alias file to alias \"Volumes:Students:${userGrade}:${userid}\" at desktop"

Need help with logon Script

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.