Automatically renaming downloaded files on Mac

时间:2019-01-07 13:26:36

标签: macos file rename automator renaming

I've been trying to find a way to automatically rename my downloaded files on my Macbook Pro, but I somehow can't. I've tried using Automator and having a folder action that renames the files coming into the folder, but somehow it doesn't work at all, as if it was disabled.

Does anybody have any idea on how I could rename them automatically when they're downloaded, so that it's easier to keep them in order (mainly for myself), for archiving reasons.

The way I want to rename them is simply to add the creation date to it, just like this script should work.

Folder Script Automator

However, this does rename them, but it never stops, it keeps adding the date in eternity, and of course I'd only like it once in the beginning.

What it really does

1 个答案:

答案 0 :(得分:0)

将下面的AppleScript代码在Script Editor.app中保存为“ Move And Rename.scpt”到您的文件夹中…/ Users /您的简短名称/ Library / Workflows / Applications / Folder Actions /

要能够使用文件夹操作重命名文件,必须将要重命名的文件移至其他文件夹,否则会产生无限循环

您唯一需要做的就是在您的下载文件夹中创建一个文件夹,并将其命名为…重命名文件。这是重命名文件的放置位置

on adding folder items to theFolder after receiving theNewItems
    tell application "Finder" to set theNewItems to files of folder theFolder

    repeat with i from 1 to count of theNewItems
        set theFile to item i of theNewItems
        set moveToFolder to (path to downloads folder as text) & "Renamed Files:"

        set AppleScript's text item delimiters to ","
        set theLongDate to (current date)
        set theLongDate to (date string of theLongDate)
        set currentMonth to (word 1 of text item 2 of theLongDate)
        set currentDay to (word 2 of text item 2 of theLongDate)
        set currentYear to (word 1 of text item 3 of theLongDate)
        set monthList to {January, February, March, April, May, June, ¬
            July, August, September, October, November, December}
        repeat with x from 1 to 12
            if currentMonth = ((item x of monthList) as string) then
                set theRequestNumber to (text -2 thru -1 of ("0" & x))
                exit repeat
            end if
        end repeat
        set currentMonth to theRequestNumber
        set currentDay to (text -2 thru -1 of ("0" & currentDay))
        set theShortDate to (currentYear & "-" & currentMonth & "-" & currentDay) as string

        set newName to theShortDate

        tell application "Finder"
            set theName to name of theFile
            move theFile to moveToFolder
            set theFile to moveToFolder & theName
            try
                set name of alias theFile to newName & " " & theName
            on error errMsg number errNum
                set name of alias theFile to newName & " 1 " & theName
            end try
        end tell
    end repeat
end adding folder items to

将文件保存到该位置后,即可将其作为文件夹操作附加到在Finder.app中选择的任何文件夹

enter image description here

enter image description here