macos - 在 Mac 上自动重命名下载的文件
问题描述
我一直在尝试找到一种方法来自动重命名我在 Macbook Pro 上下载的文件,但不知何故我做不到。我试过使用 Automator 并有一个文件夹操作来重命名进入文件夹的文件,但不知何故它根本不起作用,就好像它被禁用了一样。
有没有人知道我如何在下载它们时自动重命名它们,以便出于归档原因更容易保持它们的顺序(主要是为了我自己)。
我想重命名它们的方法只是添加创建日期,就像这个脚本应该工作一样。
然而,这确实重命名了它们,但它永远不会停止,它会不断地添加日期,当然我一开始只喜欢它一次。
解决方案
将 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 中选择的任何文件夹
推荐阅读
- ruby - People API:无法克服错误:rateLimitExceeded:资源已用尽
- android - Android Jetpack Compose 中数据类的更新策略
- tensorflow - 将 keras 模型另存为 .h5
- html - 如何在引导程序中对齐按钮工具栏
- python - 如何使用 selenium python 访问这个chartink按钮
- xml - 如何定义备选方案的封闭联合
- java - 无法在 Java 中使用空格打印任何内容。只有第一个单词被打印,其他单词被跳过
- d3.js - d3js - 在刻度带中缺少刻度
- apache-kafka - 激活压缩的 Kafka 消息大小
- javascript - Mustache.js 未在 html 标记内呈现禁用属性。但它在其他地方正确渲染