Hello!
So, I’m wondering if anyone might be able to help me solve a very mundane task with some Applescripting.
What I need to do every day is take a folder:
JenniferB 05-03_ECOMM <–Date Created timestamp 8:14 AM
BenG 05-03_ECOMM <–Date Created timestamp 11:39 AM
and rename it differently based on the time it was created (for this example 08:14am) as well as moving some of the characters to a different location in the folder name:
05-03_0814_ECOMM JenniferB
05-03_1139_ECOMM BenG
I usually have about 30-50 of these a day and each folder has a unique timestamp. Is this something possible with Applescript?
Thanks,
Jason
Hi,
this is a solution for renaming the folder.
It assumes the naming pattern [name] [date]_[type] containing only one space and one underscore character
set theFolder to choose folder
tell application "Finder"
set {minutes:mins, hours:hrs} to creation date of theFolder
set folderName to name of theFolder
end tell
try
set {TID, text item delimiters} to {text item delimiters, "_"}
set {prefix, suffix} to text items of folderName
set text item delimiters to space
set {theName, theDate} to text items of prefix
set text item delimiters to TID
set newFolderName to theDate & "_" & hrs & mins & "_" & suffix & space & theName
tell application "Finder" to set name of theFolder to newFolderName
on error
display dialog "the name of the folder doesn't match the naming pattern"
end try
Wow, that’s fantastic. But I have two questions of altering it.
First, can we make it so that I can just drop 30 folders that need to be renamed on to the scripting app?
Second, if the time is 7:36am, can it read out with a leading 0, such as 07:36?
Brilliant script, by the way.
Cheers,
Jason
try this, save the code as application (bundle)
on open theseItems
repeat with anItem in theseItems
tell application "Finder"
set isFolder to (get class of item (anItem as text)) is folder
set {minutes:mins, hours:hrs} to creation date of anItem
set folderName to name of anItem
end tell
if isFolder then
try
set {TID, text item delimiters} to {text item delimiters, "_"}
set {prefix, suffix} to text items of folderName
set text item delimiters to space
set {theName, theDate} to text items of prefix
set text item delimiters to TID
set newFolderName to theDate & "_" & text -2 thru -1 of ("00" & hrs) & mins & "_" & suffix & space & theName
tell application "Finder" to set name of contents of anItem to newFolderName
on error
display dialog "the name of the folder doesn't match the naming pattern"
end try
end if
end repeat
end open
Stephan,
Once again, you’re a genius. Thanks for the help.
Jason