【问题标题】:Applescript move file to custom folderApplescript 将文件移动到自定义文件夹
【发布时间】:2014-02-05 03:35:53
【问题描述】:

我正在尝试制作一个 Applescript,将聚焦文件移动到对话框指定的文件夹中。我希望脚本找到我输入的文件夹的路径,但是我无法让它工作。任何人都可以帮忙吗?如果你能告诉我为什么我的代码在我的预览中没有全部进入一个块,请提前感谢和加分:(!!

问题出在星号开始和结束的地方。

这里是代码。

 repeat 1 times

    set spotlightquery to quoted form of text returned of (display dialog "What do you want to search?" default answer "" buttons {"Search!"} default button 1)

    if spotlightquery = "''" then
        exit repeat
    end if
    set thefolders to {path to home folder}
    set founditems to {}
    repeat with i in thefolders
        set thepath to quoted form of POSIX path of i
        if exists thepath then
            set command to "mdfind -onlyin " & thepath & " " & spotlightquery
            set founditems to founditems & (paragraphs of (do shell script command))
        end if
    end repeat
    if founditems = {} then
        display dialog "No items found." buttons {"OK"} default button 1
        exit repeat
    end if

    display dialog "" & founditems & "" buttons {"OK"} default button 1
    set location to the button returned of (display dialog "Where would you like to move it?" buttons {"C Folder", "Desktop", "Other"} default button 3)
    if location = "C Folder" then
        tell application "Finder"
            set moveTo to "Macintosh HD:Users:aaronmcclellan:Desktop:Coding:C"
            move file founditems to folder moveTo
        end tell
    else
        if location = "Desktop" then
            tell application "Finder"
                set moveTo to the path to desktop folder
                move file founditems to folder moveTo
            end tell
        end if
        *if location = "Other" then
            set fold to the text returned of (display dialog "Where would you like to move it?" default answer "" buttons {"OK"} default button 1)
            set moveTo to fold
            tell application "System Events"
                ##error occurs here
                            move file founditems to folder moveTo
            end tell
        end if*
    end if
  end repeat

【问题讨论】:

  • 你真的应该先调试并找出哪条线出错了。将显示对话框放在检查点并验证变量是否正确。然后你可以问为什么一个特定的行或块不工作,而不是整个例程。
  • 我在代码开始失败的地方添加了星号。谢谢!
  • 您到底在哪一行得到错误,究竟是什么错误?
  • 是的,否则很难提供帮助。在 if 块周围包裹一个 Try 块并报告报告的错误。其他问题:C 文件夹和桌面选项是否有效?为什么您使用 DispDialog 而不是 Other 的选择文件夹对话框?您是在 old:mac:format 还是 posix/path/format 中键入文件夹路径?如果是 posix,则需要更改移动线以适应。
  • 对不起大家。我有工作要做,所以我无法帮助并阅读您的 cmets。我添加了错误发生的位置。

标签: applescript


【解决方案1】:

您有这两行...我相信您希望这两个变量匹配?

set getMovedTo to "Macintosh HD:Users:aaronmcclellan:Desktop:Coding:C"
move file founditems to folder moveTo

【讨论】:

  • 你是对的。但是,这是一个简单的解决方法。感谢您指出。
【解决方案2】:

foundItems 是一个字符串列表,但您正试图将其视为文件。移动线的评估方式如下:

move (file founditems) to (folder moveTo)

这会导致错误,因为列表foundItems 无法转换为文件。

您需要将每个路径分别转换为一个文件:

repeat with theFile in foundItems
    move file theFile to folder moveTo
end repeat

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多