Applescript 无法设置文件名

Applescript can't set name of file

所以我正在尝试使用 Applescript 重命名文件。我搜索了一下,显然命令是 set name of file theFile to theString。我试过了,但没有用。我收到错误 -10006,(根据 https://www.osstatus.com)是 errAEWriteDeniederrOSACantAssigntelCAUnavail,但我认为它可能是第一个。在你问之前,我是我机器的管理员,path to desktop 链接到我 100% 可以访问的自己的桌面。我不知道这是否重要(真的不应该),但我的桌面存储在我的 iCloud 中。

set thePath to the POSIX path of (path to desktop)
set theName to "hello world.txt"
set theFile to thePath & theName
set the name of file theFile to "hello.txt"

只有FinderSystem Events可以设置名称。在 Finder 中,这很容易,因为当前用户的桌面是根文件夹。

tell application "Finder"
    set theFile to "hello world.txt"
    set theName to "hello"
    set the name of file theFile to theName & ".txt"
end tell

顺便说一下,Finder 不知道 POSIX 路径,它更喜欢 HFS 路径(冒号分隔)