首页 > 解决方案 > 在 Mac 上自动重命名下载的文件

问题描述

我一直在尝试找到一种方法来自动重命名我在 Macbook Pro 上下载的文件,但不知何故我做不到。我试过使用 Automator 并有一个文件夹操作来重命名进入文件夹的文件,但不知何故它根本不起作用,就好像它被禁用了一样。

有没有人知道我如何在下载它们时自动重命名它们,以便出于归档原因更容易保持它们的顺序(主要是为了我自己)。

我想重命名它们的方法只是添加创建日期,就像这个脚本应该工作一样。

文件夹脚本自动化

然而,这确实重命名了它们,但它永远不会停止,它会不断地添加日期,当然我一开始只喜欢它一次。

它的真正作用

标签: macosfilerenameautomatorrenaming

解决方案


将 Script Editor.app 中的以下 AppleScript 代码保存为“Move And Rename.scpt”到您的文件夹... /Users/YOUR SHORT NAME/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 中选择的任何文件夹

在此处输入图像描述

在此处输入图像描述


推荐阅读