语法错误:预期行结束但发现未知令牌

时间:2022-08-11 22:31:22

I am attempting to run some AppleScript in the terminal, just to learn how to do it, and I am running into some trouble with the & sign. Even when the & is replaced with the "&", it still returns the same error.. I have narrowed it down to the problem with the & sign, and am wondering if anyone has any advice about it. I am getting the following error:

我试图在终端中运行一些AppleScript,只是为了学习如何做到这一点,并且我在使用&符号时遇到了一些问题。即使将&替换为“&”,它仍会返回相同的错误。我已将其缩小到&符号的问题,并且我想知道是否有人对此有任何建议。我收到以下错误:

syntax error: Expected expression but found unknown token.

语法错误:预期的表达式,但发现未知的令牌。

My code that I type into the terminal:

我输入终端的代码:

osascript -e 'tell application "Finder"' -e 'set location to (path to home folder as string) & \"testing.plist\"' -e 'if (exists file location) then' -e 'say location' -e 'end if' -e 'end tell'

osascript -e'告诉应用程序“Finder”'-e'将位置设置为(主文件夹的路径为字符串)&\“testing.plist \”' - e'if(存在文件位置)然后'-e'表示位置' -e'如果'-e'告诉'结束'

Thanks for any help.

谢谢你的帮助。

1 个解决方案

#1


You don't need the backslashes to escape the double quotes for "testing.plist", removing those will fix that error.

您不需要使用反斜杠来转义“testing.plist”的双引号,删除它们将修复该错误。

Additionally, the word "location" is used by the Finder dictionary, so you'll want to use some other term for that variable, such as "myLocation" instead.

此外,“位置”一词由Finder字典使用,因此您需要为该变量使用其他一些术语,例如“myLocation”。

#1


You don't need the backslashes to escape the double quotes for "testing.plist", removing those will fix that error.

您不需要使用反斜杠来转义“testing.plist”的双引号,删除它们将修复该错误。

Additionally, the word "location" is used by the Finder dictionary, so you'll want to use some other term for that variable, such as "myLocation" instead.

此外,“位置”一词由Finder字典使用,因此您需要为该变量使用其他一些术语,例如“myLocation”。