I'm new to AppleScript so I'm sure it's something obvious. This works if I have selected multiple files (I use it with the right-click context menu), but if one file is selected, nothing happens (no errors).
The intention is to take some file called someRandom-imageIdontremember.jpg
and use its Creation Date to rename to 2005-03-01_someRandom-imageIdontremember.jpg
and likewise if I select multiple files.
on run {input, parameters}
tell application "Finder"
set selectedFiles to (get selection)
repeat with i from 1 to (count selectedFiles)
set aFile to item i of selectedFiles
set fileName to name of aFile
set {year:y, month:m, day:d} to creation date of aFile
set dateStamp to (y as text) & "-" & text -2 thru -1 of ("0" & (m as integer)) & "-" & ¬
text -2 thru -1 of ("0" & d)
set name of aFile to dateStamp & "_" & fileName
end repeat
end tell
return input
end run
Any suggestions/ideas are appreciated.
Run AppleScript
action the workflow arguments (selection, whatever) are already being passed in theinput
argument.