Applescript错误-无法获取...文件夹的每个文件?

时间:2019-10-10 02:16:34

标签: applescript

我有一个别人写的脚本。它可以在他的计算机上工作,但不能在我的计算机上工作。

最初它说"as alias",但我不断收到如下错误消息:

  

"Can’t make file "Macintosh HD:Users:williamsato:Desktop:Photobooth:CurrentSession" into type alias."

因此,我根据另一篇文章中的建议,将alias更改为string

现在我没有收到该错误消息,但确实收到了一条新消息,如下所示:

  

"Can’t get every file of "Macintosh HD:Users:williamsato:Desktop:PhotoBooth:CurrentSession"."

它突出显示了行“ ”“将SourceFolder的文件替换为DestinationFolder”

不知道出了什么问题。

谢谢

on run {input, parameters}
    set SourceFolder to POSIX file "/Users:/williamsato/Desktop/Photobooth/CurrentSession" as string
    set DestinationFolder to POSIX file "/Users/williamsato/Desktop/Photobooth/PreviousSessions" as string

    tell application "Finder"
        move files of SourceFolder to DestinationFolder with replacing
    end tell
    (* Clear Large Type *)
    tell application "System Events" to keystroke "a" using command down
end run

1 个答案:

答案 0 :(得分:0)

以下是形成SourceFolderDestinationFolder 变量并移动文件的三种不同方式:

set SourceFolder to (path to desktop folder as string) & "Photobooth:CurrentSession:" as alias
set DestinationFolder to (path to desktop folder as string) & "Photobooth:PreviousSessions:" as alias

tell application "Finder" to move files of SourceFolder to DestinationFolder with replacing

set SourceFolder to alias "Macintosh HD:Users:williamsato:Desktop:Photobooth:CurrentSession:"
set DestinationFolder to alias "Macintosh HD:Users:williamsato:Desktop:Photobooth:PreviousSessions:"

tell application "Finder" to move files of SourceFolder to DestinationFolder with replacing

set SourceFolder to POSIX file "/Users/williamsato/Desktop/Photobooth/CurrentSession" as alias
set DestinationFolder to POSIX file "/Users/williamsato/Desktop/Photobooth/PreviousSessions" as alias

tell application "Finder" to move files of SourceFolder to DestinationFolder with replacing

注意:示例 AppleScript 代码就是这样,并且不包含任何 error 处理适当。用户有责任添加适当的,需要的或想要的任何错误处理。看看try中的error 声明AppleScript Language Guide 声明。另请参见Working with Errors