Button for adding dates to filenames.

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).
(edited on 10 May 2019 in response to Ajdinm)

    {
      "BTTTriggerType" : 633,
      "BTTTriggerTypeDescription" : "Date \/ Time Widget",
      "BTTTriggerClass" : "BTTTriggerTypeTouchBar",
      "BTTPredefinedActionType" : 172,
      "BTTPredefinedActionName" : "Run Apple Script (blocking)",
      "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" : 17,
      "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
      }
    }

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)

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

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!

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

1 Like

Hi, this is great button which would also help me in daily workflow. Thanks!

However, it doesn't seem to work for me, when I copy your JSON action isn't created. Any idea why?

Hi,
thanks for the message. I tried it again, it didn't seem to work anymore indeed. Can you try the code below and see if it works with you now?

  {
      "BTTTriggerType" : 633,
      "BTTTriggerTypeDescription" : "Date \/ Time Widget",
      "BTTTriggerClass" : "BTTTriggerTypeTouchBar",
      "BTTPredefinedActionType" : 172,
      "BTTPredefinedActionName" : "Run Apple Script (blocking)",
      "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" : 17,
      "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
      }
    }

This works, thanks :smiley: