使用Applescript将文件移动到文件夹中

时间:2015-04-30 14:27:44

标签: applescript

我对学习AppleScript很新,我试图为学校的公告系统设置一些东西,以使其更加自动化。这应该是当前日期,检查月份的文件夹是否存在,以及它是否创建了一个。然后它应该将公告文件移动到该文件夹​​中。

出于某种原因,这个工作正常,直到将一个文件夹添加到包含所有其他文件夹的桌面(我不知道为什么,但这对我的学校来说非常正常)。无论如何,我不得不编辑文件路径,现在它无法正常工作。任何帮助将不胜感激。

property parentFolder : ((path to desktop folder) & "DESKTOP_NEWS")

on run argv

    set myFile to item 1 of argv
    set myMonth to month of (current date)

    set currentMonthFolder to myMonth & space & "Announcements" as text


    tell application "Finder"
        if not (exists folder currentMonthFolder of parentFolder) is true then
            make new folder at parentFolder with properties {name:currentMonthFolder}
        end if

        move myFile to folder currentMonthFolder of parentFolder

    end tell
end run

1 个答案:

答案 0 :(得分:0)

我刚测试了这个(移动部分除外),它按预期工作。主要是parent_folder被错误地创建了。

property parentFolder : (((path to desktop folder) as text) & "DESKTOP_NEWS" as alias)

on run argv

    set myFile to item 1 of argv
    set myMonth to month of (current date)

    set currentMonthFolder to (myMonth & space & "Announcements") as text

    tell application "Finder"
        if not (exists folder currentMonthFolder of parentFolder) then
            make new folder at parentFolder with properties {name:currentMonthFolder}
        end if

        move myFile to folder currentMonthFolder of parentFolder

    end tell
end run