示例 AppleScript 代码(如下所示)在macOS Catalina和macOS Big Sur下的脚本编辑器中进行了测试,系统偏好设置中的Language & Region设置设置为English (US) — Primary并且为我工作,没有问题1。
要解决此问题,请在Script Editor中,仅使用 .eg,:
set theURL to "http://apple.com/myfile" as URL
--set t to theURL as text --Fails, can't coerce to text
set a to scheme of theURL --works
set b to host of theURL --works
set c to path of theURL --fails
至少要添加到脚本use scripting additions
的顶部。您可能还需要添加什么。use AppleScript version "2.4" -- Yosemite (10.10) or later
因此,在Script Editor中,例如:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set theURL to "http://apple.com/myfile" as URL
set c to path of theURL
笔记:
与path
作为关键字(或保留)没有冲突,因为它只是不是关键字!请参阅:AppleScript 关键字
另请参阅标准添加的脚本编辑器中的库下面的屏幕截图。
此问题完全是由于use scripting additions
必须在您的示例 AppleScript 代码的上下文中使用这一事实。
假设您正在运行Yosemite (10.10)或更高版本,一般来说,将上述行添加到您的脚本通常是安全的。我个人只根据需要添加它们。
- 1 假设系统偏好设置>安全和隐私>隐私中的必要和适当设置已根据需要进行设置/解决。

从标准添加的脚本编辑器( ⇧⌘L ) 中的库:

如您所见path
,它是URL的文本只读属性,并且在使用如上所示时很容易检索。use scripting additions
更新:
为了反驳罗伯特·克尼亚齐迪斯在我的回答下的评论中对我提出的虚假指控,...

...在我发表评论时引用了他的答案,这是他最近重写他之前删除的答案后拍摄的三个屏幕截图,并且自我发表评论以来,这证实了我所说的话。
在第一个屏幕截图中,我再次将第一个代码块复制并粘贴到Script Editor中,可以看到它是紫色的,这意味着它还没有被编译。

第二个屏幕截图显示点击了运行 按钮,它编译代码并执行它。可以清楚地看到,它完全按照我之前所说的进行,它自动更改set c to «property FTPc» of theURL
为set c to path of theURL
并导致我提到的错误,这在 OP 中也提到了,并且是所提问题的问题!

在第三个屏幕截图中,我再次添加use scripting additions
并运行了脚本,产生了预期的输出,并且没有像 OP 中的错误或我被指控撒谎的事实陈述。

我能够在两台不同的机器上使用Script Editor ( AppleScript的Apple默认应用程序)和Script Debugger(一种旨在优于Script Editor的第三方应用程序)在macOS Catalina和macOS Big Sur中复制这些结果。