在applescript中将字符串和变量连接成字符串

发布于 2024-12-01 18:52:35 字数 332 浏览 0 评论 0原文

我必须编写一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天生の放荡 2024-12-08 18:52:35

path 不能是变量名。

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

工作正常。

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.

尐偏执 2024-12-08 18:52:35

我同意伯特兰的观点,你的问题是使用“路径”作为变量。有些单词对 applescript 有特殊含义,不能用作变量,路径就是其中之一。您会注意到,当您编译代码时,该路径不会像其他变量那样变成绿色,表明它是特殊的。

如果您仍然想使用“path”作为变量,也可以。在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

请注意,使用这种技术,您实际上可以在几个单词中使用一个变量,例如...

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

最后一条评论...有一种 applescript 方法可以获取一个人的短用户名...

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

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文