Archive for July, 2024

Customizing the suggested filename in Save dialogs

Thursday, July 25th, 2024

I got a request from a Default Folder X user yesterday, asking if I could add a feature to limit the length of the default filename supplied in Save As dialogs. Apparently, the cloud services and backup software that he and his colleagues use can’t handle filenames longer than 45 characters, so he wants to make sure they don’t save files with names longer than that. That’s a pretty unfortunate limitation of the software they’re using (I mean really, in 2024?), but I’m all for avoiding stupid problems.

I’ve addressed a similar request before, automatically prepending dates to the names of files as you save them. This post is an update, because Default Folder X now has a better way to handle this than the method described in that earlier post.

Background

Default Folder X has a flexible, AppleScript-based method for handling customized default folders and filenames in Save dialogs. Yeah, I know AppleScript is old and crufty, but it’s available on every Mac, can interoperate with other apps, and allows you to cobble together just about anything, so it’s a good solution here. Anyway, when a file dialog appears on the screen, Default Folder X looks for and runs special AppleScripts if they’re present, allowing you to use any logic you want to determine the starting location (the “default folder”) for a file dialog, and the name of the file suggested in Save As dialogs.

The AppleScripts should be located in this folder:

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

where the ‘~’ character denotes your home folder. Default Folder X looks for scripts with predetermined names, depending on their purpose:

  • getDefaultFilename.scpt – modifies the suggested filename in Save As dialogs
  • getDefaultFolder.scpt – specifies the default folder for an Open or Save dialog

Note that the scripts must be saved with those names in order for them to work. If you want a script to only run in the Open and Save dialogs of a single application, put it in a subfolder with the same name as the app. For example, to have scripts that only run in Safari, save them in:

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

The implementation details (the name of the AppleScript handler and the arguments that Default Folder X passes to it) are included at the beginning of each of these sample scripts:

Truncating Long Filenames

OK, back to the task at hand. In this case, we want to provide a “getDefaultFilename” handler that truncates the default filename in Save dialogs to no more than “maxLength” characters.

Here’s the AppleScript:

on getDefaultFilename(appName, suggestedName, fileExtension)

  -- Specify our maximum filename length
  set maxLength to 45
  
  -- Make sure the filename extension isn't counted
  set addExtension to false
  if fileExtension is not "" and suggestedName ends with fileExtension then
    set suggestedName to text 1 thru -((count fileExtension) + 2) of suggestedName
    set addExtension to true
  end if
  
  -- Truncate the filename
  if length of suggestedName is greater than maxLength then
    set newName to text 1 thru maxLength of suggestedName
  else
    set newName to suggestedName
  end if
  
  -- Add the extension back on if appropriate
  if addExtension is true then
    set newName to newName & "." & fileExtension
  end if
  
  -- And give the name to Default Folder X
  return newName

end getDefaultFilename

Enter the code above in Script Editor and save it as an AppleScript script or download GetDefaultFilename.zip. Save the “GetDefaultFilename.scpt” file in this location:

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

Each time a Save As dialog appears, it will magically truncate any filenames longer than 45 characters. Note that you can still edit the name afterwards in the Save dialog if you don’t like the one created by the script.

Credit Where Credit is Due

This scheme originated with an idea from Jason Snell (of Six Colors and The Incomparable fame) when he needed to customize the way Default Folder X worked in his podcasting workflow. I later expanded it as requests came in for customized filenames as well, and Bo Engelbrecht’s email reminded me that I’d never blogged about those updates. Thanks Jason and Bo!

Default Folder X 6.1b3 beta: Support for Warp, bug fixes and less frequent reminders from Sequoia

Wednesday, July 24th, 2024

The third beta build of Default Folder X 6.1 is available, adding support for the Warp terminal app and fixing several bugs that occurred in the previous beta (and in Default Folder X 6.0.8).

The other notable change is that this build won’t trigger Sequoia’s screen recording reminders nearly as often. Sequoia puts these up several times a day if an app is capturing screen images, which Default Folder X does as part of its normal functioning. Contrary to what this alert implies, DFX isn’t doing anything nefarious, just making its manipulations of Open and Save dialogs less jarring. The details are here. I’ve reduced the frequency of the reminders by abandoning Default Folder X’s automatic detection of dark / light mode in individual Open and Save dialogs, which required capturing an image from the screen.

To explain a bit: Some apps (including QuickTime Player, Affinity Photo, Affinity Designer and Rogue Amoeba Fission) let you change their appearance separately from the system-wide light / dark mode setting. There’s no generic way for another app like Default Folder X to tell which appearance they’re using other than taking a visual snapshot of one of the app’s file dialogs and checking to see whether it’s dark or light. I know that may sound stupid, but that’s the way macOS works – and honestly, for most normal, stand-alone applications this capability isn’t necessary, so I can understand why Apple doesn’t provide any sort of API to query an app’s appearance mode.

Anyway, without that information, Default Folder X may end up with the wrong light / dark mode for its toolbar around a file dialog, as well as for some of the controls within it – like this:

It doesn’t change the functionality that you get from Default Folder X, but it’s a bit jarring – and ugly. So, that’s the tradeoff – to stop Sequoia from whining at you every day, Default Folder X has to be less capable (and yes, I’ve filed a bug with Apple, but unless they get a lot of complaints I don’t think they’ll change this “feature” in Sequoia).

Default Folder X attempts to detect these situations using a different, application-specific method, and will currently do the right thing with the above-mentioned apps (QuickTime, Affinity apps and Fission). If you encounter this mismatch in other apps, let me know at DefaultFolderX@stclairsoft.com and I’ll do my best to find a way to detect the appearance for that app.

Grumble.

At any rate, a full change history and download links for Default Folder X 6.1b3 are available on the Beta Testing page.

Public beta Default Folder X 6.1b2 supports Sequoia and refines web favorites

Friday, July 12th, 2024

There’s a new public beta of Default Folder X 6.1 available! In addition to updated compatibility with macOS 15 Sequoia, it improves support for web URLs that have been added as favorites. It also fixes a couple of graphical bugs.

The most useful change is the ability to go to URLs in your favorites using Quick Search. Type a bit of the name of a favorite and hit Return to open it in your browser.

Display of web URLs is better in the Favorites section of Default Folder X’s settings, and an issue with selected text appearing in the wrong color has also been fixed there. Flickering of previews in Open dialogs has also been corrected.

Note that you don’t need to be running Sequoia to use the beta – it will run on macOS 11 Big Sur and later. A full list of changes and download links is available on the Default Folder X Testing page.

Default Folder X 6.0.8 adds audio and video previews, web URL favorites and OS version checking.

Monday, July 8th, 2024

Version 6.0.8 of Default Folder X is available now, delivering several new features, plus bug fixes for recently reported problems. The big changes are playable previews of video and audio files right below Open dialogs, and the ability to store web URLs in your Favorites.

While you could always use QuickLook to preview video and audio, doing so pops up a separate window with its playback volume always set to maximum. In contrast, Default Folder X’s previews let you see the length of a recording as soon as you select it, they remember your previous volume setting, and let you quickly scrub through audio and video without opening a separate window. If you spend lots of time working with audio or video, these little details make a difference.

Adding web URLs to your Default Folder X Favorites lets you open them quickly, including assigning keyboard shortcuts to them. I really wanted this myself to access web dashboards that I use often but don’t want to leave constantly open in my browser. So there you go 🙂 Oh, and if you’ve got the Default Folder X settings window open, you can just drag URLs straight from your browser to the Favorites list.

The other new “feature” is a warning when you run Default Folder X on a system that it doesn’t support. Folks who don’t install new updates of Default Folder X right away or who are running beta versions of upcoming macOS releases will run into these alerts. Hopefully they’ll resolve the confusion, disorientation and general angst people feel when Default Folder X is missing from their Open and Save dialogs. A button takes you to a web page where you can download a newer version that works with the OS you’re running.

Default Folder X 6.0.8 also includes a few bug fixes for Quick Search, keyboard shortcuts and issues when displaying long filenames. The full change history and download links are available on the What’s New page.