Button for adding dates to filenames.

filenames
touch-bar
date

#1

This is a handy little button I use on a daily basis to date my files in a consistent way.
The button shows the date and the week number in the right corner. If you press the button it does the following through applescript:

  • If you select one or multiple files in finder, it will add the "last modification date" + "_" in front of the file name in the YYMMDD format.
  • If the selected file(s) is already dated in the above format (it will check if the 7th character is a "_"), it will remove the old date, and add again the "last modification" date.
  • If you have no file selected (for example if you want to save a new file and you are in a text input window), it will keystroke the current date in as "YYMMDD_".

Feel free to use however you like :slight_smile:

Screenshots

JSON below (copy and paste in your Touchbar Action list).

{
"BTTTriggerType" : 633,
"BTTTriggerTypeDescription" : "Date / Time Widget",
"BTTTriggerClass" : "BTTTriggerTypeTouchBar",
"BTTPredefinedActionType" : 195,
"BTTPredefinedActionName" : "Run Apple Script (async in background)",
"BTTInlineAppleScript" : "on run\r\t\r\ttell application "Finder"\r\t\tset finderList to selection as alias list\r\t\tset {year:y, month:m, day:d} to (current date)\r\t\tset theDate to (y * 10000 + m * 100 + d) as string\r\t\tset theDateShort to (text items 3 thru 8 of theDate as string)\r\t\tset frontApp to first application process whose frontmost is true\r\t\tset frontAppName to name of frontApp\r\t\t\r\t\tif (finderList is {}) or (frontAppName is not "Finder") then\r\t\t\ttell application "System Events"\r\t\t\t\tkeystroke theDateShort & ""\r\t\t\tend tell\r\t\telse\r\t\t\tset whichFile to finderList\r\t\t\trepeat with aFile in whichFile\r\t\t\t\ttell application "Finder"\r\t\t\t\t\tset filename to name of aFile\r\t\t\t\t\tset modDate to the modification date of aFile\r\t\t\t\t\tset {year:y, month:m, day:d} to (modDate)\r\t\t\t\t\tset theModDate to (y * 10000 + m * 100 + d) as string\r\t\t\t\t\tset theModDateShort to (text items 3 thru 8 of theModDate as string)\r\t\t\t\t\t\r\t\t\t\t\tif ((character 7 of filename) is "") then\r\t\t\t\t\t\tset name of aFile to theModDateShort & "" & (characters 8 thru -1 of filename as string) --trim first 6\r\t\t\t\t\telse\r\t\t\t\t\t\tset name of aFile to theModDateShort & "" & filename as string\r\t\t\t\t\tend if\r\t\t\t\t\t\r\t\t\t\tend tell\r\t\t\tend repeat\r\t\tend if\r\t\t\r\t\t\r\tend tell\r\t\rend run",
"BTTEnabled2" : 1,
"BTTUUID" : "CB0B0081-1695-4E59-8792-5D3452FAA994",
"BTTEnabled" : 1,
"BTTModifierMode" : 0,
"BTTOrder" : 15,
"BTTDisplayOrder" : 0,
"BTTMergeIntoTouchBarGroups" : 0,
"BTTTriggerConfig" : {
"BTTTouchBarButtonColor" : "0.000000, 0.000000, 0.000000, 255.000000",
"BTTTouchBarDateFormat" : "d MMM '| week 'w",
"BTTTouchBarTimeZoneLocation" : "System Time Zone",
"BTTTouchBarItemPlacement" : 2,
"BTTTouchBarItemIconWidth" : 22,
"BTTTouchBarButtonCornerRadius" : 2,
"BTTTouchBarDateWidgetTimeZone" : 3,
"BTTTouchBarAlwaysShowButton" : true,
"BTTTouchBarAlternateBackgroundColor" : "0.000000, 0.000000, 0.000000, 0.000000",
"BTTTouchBarLongPressActionName" : "AddDate",
"BTTTouchBarButtonName" : "E d MMM '| week 'w",
"BTTTouchBarFreeSpaceAfterButton" : 0,
"BTTTouchBarItemIconHeight" : 22,
"BTTTouchBarItemPadding" : 0
}
}


#2

Looks Very useful!

Could I add this to my AQT preset for it's finder widgets? I may tweak it a bit after some testing,

(also need to recover a heap of corrupted triggers becuase of a certain event that happened)


#3

Sure, feel free also to adjust to your own dating convention if you're comfortable with applescript.


#4

To be sure, this is a publicly available preset and will be uploaded with this in it for others to use. Are you still okay with the merge?

I'll credit you in the code and also link to this thread within it, forgot to mention that!


#5

Absolutely no problem, I'm just sharing what works for me so maybe it'll be helpful for others. Thanks for the credit :).