如何在AppleScript中将文件移动到垃圾箱?

Nay*_*eth 1 macos applescript

我知道它是一个愚蠢的问题但不知何故我输入的命令不起作用

set deleteFile to srcTemp & "Archive.zip"
--deleteFile path is something like this /Users/home/Desktop/Archive.zip    
tell application "Finder"
    move POSIX file "" & deleteFile & "" to trash
    --move file "\"" & destNoQuote & "Archive.zip\"" to trash
    empty the trash
end tell
Run Code Online (Sandbox Code Playgroud)

但我得到一个错误,说无法找到POSIX文件.

reg*_*633 9

我知道很多人在Finder告诉代码块中使用posix file命令,但这是一个错误.posix file命令不是Finder命令,它是一个applescript命令,因此如果可能,不应该在Finder块中.实际上对于所有命令都是如此.您应该只告诉应用程序执行您可以在其Applecript字典中找到的命令,否则您将看到意外行为......正如您所发现的那样.

因此,这就是你应该如何编写代码......

set deleteFile to srcTemp & "Archive.zip"
set posixFile to POSIX file deleteFile
--deleteFile path is something like this /Users/home/Desktop/Archive.zip    
tell application "Finder"
    move posixFile to trash
    empty the trash
end tell
Run Code Online (Sandbox Code Playgroud)

  • +1虽然在Nayan的辩护中,也有一个移动命令.你是对的,最好将它们分开. (2认同)
  • 对于记录:POSIX文件是全局类,而不是命令.无需将它们分开. (2认同)