在applescript中将字符串和变量连接成字符串
我必须编写一个 Applescript 来根据用户自动挂载文件夹。 Applescript 编辑器抛出此错误。
此标识符后面不能出现行尾。
这是引发错误的脚本部分。
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
path
不能是变量名。工作正常。
path
can't be a variable name.Works fine.
我同意伯特兰的观点,你的问题是使用“路径”作为变量。有些单词对 applescript 有特殊含义,不能用作变量,路径就是其中之一。您会注意到,当您编译代码时,该路径不会像其他变量那样变成绿色,表明它是特殊的。
如果您仍然想使用“path”作为变量,也可以。在applescript中你可以输入“|”围绕变量以向 applescript 指示它是一个变量。所以这会起作用。
请注意,使用这种技术,您实际上可以在几个单词中使用一个变量,例如...
最后一条评论...有一种 applescript 方法可以获取一个人的短用户名...
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.
Note that using this technique you can actually have one variable in several words like...
One last comment... there is an applescript method to get the short user name of a person...