21

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
Roman C
  • 49,761
  • 33
  • 66
  • 176
jeremyjjbrown
  • 7,772
  • 5
  • 43
  • 55

2 Answers2

27

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.

Bertrand Marron
  • 21,501
  • 8
  • 58
  • 94
11

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)
regulus6633
  • 18,848
  • 5
  • 41
  • 49