Reputation: 522
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.
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.
Upvotes: 0
Views: 1552
Reputation: 3142
Save this following AppleScript code in Script Editor.app as “Move And Rename.scpt” to your folder… /Users/YOUR SHORT NAME/Library/Workflows/Applications/Folder Actions/
To be able to rename the files using a folder action, the files to be renamed must be moved to a different folder otherwise it will create an infinite loop
The only thing you need to do is create a folder in your downloads folder and name it … Renamed Files. This is where the renamed files will be placed
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
Once you have saved that file to that location, it will then be ready to attach to any folder you choose in Finder.app as a folder action
Upvotes: 1