Apple Script

anuraj

Registered
hey guys,

I was wondering if someone can help.

I am after a apple script that will mount a volume from a network machine.

basically:

afp://10.1.5.125/serverpartition


I want to plug it with automator so i can mount all my network drive when i want, without having to specify username and passwords for each, all the time.

i found this script, but it doesnt seems to work! maybe someone can help debug?

Script:

tell application “Finder”
–activate
try
mount volume “afp://10.1.5.125/serverpartition” as user name “«your user id»” with password “«your password»”
on error
display dialog “There was an error mounting the Volume.” & return & return &
“The server may be unavailable at this time.” & return & return &
“Please inform the Network Administrator if the problem continues.” buttons {”Okay”} default button 1
end try
end tell

If i paste in like that, i get errors!


Thanks guys!

Anuraj Singh
 
There are three reasons it's causing errors:

1. AppleScript does not like "smart" quotes. You need to change them to normal quotes.
2. AppleScript does not like em-dashes (—). OS X automatically converts double-dashes (--) to em-dashes in some apps. Doubke-dashes in AppleScript mark comments. Either remove the em-dash entirely to exectute the "activate" command, or change it to a double-dash to comment it out
3. There are artificial line breaks in the ridiculously-long "display dialog" line. Strip 'em out, or replace the returns with Option-returns in Script Editor (option-return means "treat the next line like it's part of this line").

The repaired script should look something like this (hopefully it won't be messed up when I paste it in here...)
Code:
tell application "Finder"
	activate
	try
		mount volume "afp://10.1.5.125/serverpartition" as user name "«your user id»" with password "«your password»"
	on error
		display dialog "There was an error mounting the Volume." & return & return & "The server may be unavailable at this time." & return & return & "Please inform the Network Administrator if the problem continues." buttons {"Okay"} default button 1
	end try
end tell
 
Back
Top