Archive for September, 2020

Automatically prepending dates to the names of saved files

Wednesday, September 9th, 2020

So a Default Folder X user just emailed and asked this:

I have been a Mac user for 30 years and would love to find a tool that allows me to click a button (or make this the default filename) while in the “Save…” dialog box that will prepend a formatted date to the beginning of the filename. like so:

2020-09-08 Filename.ext

Now, you can set up an AppleScript to do this using Default Folder X’s GetSaveName and SetSaveName verbs. However, that would require that you run the AppleScript whenever you want the date prepended, which is a bit of a pain if you want all of your filenames formatted this way. But I realized as I was replying that you can actually automate this by using (or rather, slightly abusing) an existing feature in Default Folder X.

Default Folder X has the ability to run an AppleScript to determine the location of an application’s default folder. The script will be run whenever a new file dialog is displayed by an application, which is the perfect time to do our little filename modification. So I wrote an AppleScript that looks like this:

on getDefaultFolder(appName, dialogType, firstTime)

  -- only do this for save dialogs
  if dialogType is "save" then

    -- get the current date
    set dateObj to (current date)

    -- then format it as YYYY-MM-DD
    set theMonth to text -1 thru -2 of ("0" & (month of dateObj as number))
    set theDay to text -1 thru -2 of ("0" & day of dateObj)
    set theYear to year of dateObj
    set dateStamp to "" & theYear & "-" & theMonth & "-" & theDay

    -- then prepend that to the name in the save dialog
    tell application "Default Folder X"
      set theName to GetSaveName
      set theName to dateStamp & " " & theName
      SetSaveName theName
    end tell
  end if

  -- finally, don't give Default Folder X a default
  -- folder, so it just continues on normally 
  return ""
end getDefaultFolder

If you save this script in a file named “GetDefaultFolder.scpt” in this location:

~/Library/Application Support/com.stclairsoft.DefaultFolderX5/Scripts/

It will magically prepend the date in the format ‘2020-09-15’ to the beginning of all of your filenames in Save As dialogs. Note that you can still edit the name afterwards if the default filename (like “Untitled 4”) needs to be modified.

Jettison 1.8.1 fixes what broke in version 1.8

Wednesday, September 9th, 2020

Well, Jettison 1.8 didn’t go quite as planned. It adopted a different system API to get power notifications so that it could better handle “dark wake” events, where macOS wakes up briefly to perform backups and network maintenance while it’s sleeping. While the dark wake stuff all worked as expected, it ended up causing issues with some external drives not getting ejected before sleep because sleep notifications were delivered slightly later in the going-to-sleep sequence. It didn’t make a difference on test machines here or with our beta testers, but impacted some users out in the real world once version 1.8 was released. If you’re one of those folks, I’m sorry for the trouble 🙁

Version 1.8.1 was released today, and takes a hybrid approach, using both the old and new API’s to ensure that it gets sleep notifications as early as possible. This restores the reliability of Jettison’s eject-on-sleep capabilities.

This release also allows you to turn off the feature introduced in version 1.8 that quits Music, iTunes and Photos before sleep (to allow ejection of external media containing music and photo libraries). Apparently iTunes doesn’t correctly return to the same location in audiobooks when Jettison relaunches it after waking up, which can be really annoying. So you can disable the feature by using this command in Terminal:

defaults write com.stclairsoft.Jettison leaveAppsRunning 1

As usual, full release notes and download links are on the Jettison release page.