Alex Rivera | Logout

concatenate a string and a variable into a string in applescript

Asked 2011-08-26T20:22:37.353
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
Edit
Report

1 Answer

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)
answered 2011-08-27T06:41:54.810

Your Answer