I’d like to bulk rename files using the following convention. I’d like to be able to append as many tags as there are attached to a file, ideally in alphabetical order.
Is there a way to do this without AppleScript? (Unfortunately AS is beyond my abilities)
The dates could be done with placeholders. However, the tags can’t be processed and presented that way without some scripting. And no, RegEx wouldn’t work in this case.
on run
tell application id "DNtp"
if selection = {} then return
my performSmartRule(selected records)
end tell
end run
on performSmartRule(theRecords)
set od to AppleScript's text item delimiters -- Cache the default text item delimiter
tell application id "DNtp"
repeat with theRecord in theRecords
set recordTags to (tags of theRecord) -- Cache the tags
set cd to creation date of theRecord -- Get the creation date
-- Assign variables to the date components
set yyyy to year of cd
set mm to (month of cd) as integer
set dd to day of cd
set dateString to {yyyy, (my zeropad(mm as integer)), my zeropad(dd)} -- Order the date components in a list
set AppleScript's text item delimiters to "_" -- Assign the date delimiter
set dateString to dateString as string -- Process the list as a string
set AppleScript's text item delimiters to "-" -- Switch to a delimiter for the tags
set newName to {dateString, recordTags} as string -- Concatenate the date and tags with the delimiter
set AppleScript's text item delimiters to od -- Reset the text item delimiter
set name of theRecord to newName -- Apply the new name
end repeat
end tell
end performSmartRule
on zeropad(num) -- Add prefixing zero (from @cgrunenberg)
return (characters -2 thru -1 of ("0" & num as string)) as string
end zeropad
Last question: how do I edit this so that all delimiters are simply underscores? I tried editing the Applescript itself but it doesn’t seem to affect the end result at all.
I tried that but it doesn’t work, unfortunately! The batch rename seems to perform exactly the same as the previous script. (And yes, I’ve saved the script as a new name and I’m positive it’s running the right one.)