24

I have to write an Applescript to automount a folder depending on the user. Applescript Editor throws this error.

A end of line can’t go after this identifier.

Here the portion of the script that is throwing the error.

try
    set short_name to do shell script "whoami"
    set path to "afp://fileserver.local/Faculty/" & short_name
    mount volume path as user name short_name
end try
2
  • I should add that the short_name at the end of line 3 is highlighted. Commented Aug 26, 2011 at 20:25
  • A quick side note: You shouldn't be seeing any errors since your script is in a try block. Commented Aug 27, 2011 at 13:15

2 Answers 2

29

path can't be a variable name.

try
    set short_name to do shell script "whoami"
    set p to "afp://fileserver.local/Faculty/" & short_name
    display dialog p
end try

Works fine.

Sign up to request clarification or add additional context in comments.

Comments

12

I agree with Bertrand, your problem is with using "path" as a variable. Some words have a special meaning to applescript and can't be used as a variable, path being one of them. You'll notice that when you compile your code that path doesn't turn green like other variables indicating it's special.

If you still wanted to use "path" as the variable you can though. In applescript you can put "|" around the variable to indicate to applescript that it is a variable. So this would work.

try
    set short_name to do shell script "whoami"
    set |path| to "afp://fileserver.local/Faculty/" & short_name
    mount volume |path| as user name short_name
end try

Note that using this technique you can actually have one variable in several words like...

set |the path| to "afp://fileserver.local/Faculty/" & short_name

One last comment... there is an applescript method to get the short user name of a person...

set short_name to short user name of (get system info)

2 Comments

+1, but I'll disagree with you on set short_name to short user name of (get system info). On my machine it takes about 2 seconds to run.
I agree (get system info) is very slow. "do shell script "whoami" " is much faster

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.