Default Folder X: Using AppleScript to specify default folders on the fly

Version 5.3.7 of Default Folder X introduced a new capability: it can now ask what the default folder for an application should be on the fly using AppleScript. That may sound like a mouthful of jargon, so let me explain, because it can be applied in a lot of situations.

Jason Snell (of Six Colors and The Incomparable fame) has been writing about Macs forever, and is now a prolific podcaster. He emailed to ask if it would be possible to make Default Folder X more flexible. At that time, you could set a default folder for an application so that when you chose Save As, it always offered to save a file in that particular folder. His problem was that you have to set a single folder as the app’s default folder – just one.

Jason creates podcasts – lots of them. His reasoning was that if he could magically tell Default Folder X what podcast he was working on, it would always offer to save the component audio files into the folder for that podcast. Essentially: Wouldn’t it be great if you could edit an audio clip, hit Save, and have it automatically go into the folder for the current podcast folder? No re-configuring a default folder for each new project – it’d just work.

So he hit on this idea (which I think is just brilliant). He uses Apple’s Logic X application to create his podcasts. So for each podcast episode, there’s one master Logic X project file. To find the correct default folder for audio clips, all he has to do is look at all the project files and see which one has been saved most recently. The “Audio Files” folder sitting next to that project is where everything should go for the current project. He wrote an AppleScript to do this, which he shared on the Six Colors blog.

This can obviously translate to all sorts of different workflows. If you have one primary file for each project, it’s easy to tell which one you’re currently working on – it’s the one that’s been saved most recently.

How to set up an AppleScript to specify a default folder

So how do you wire up Default Folder X to do this? It’s pretty simple. Put an AppleScript script in:

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

or, if you want it to handle only a single application, put it in a sub-folder of the Scripts folder named for the application you want it to serve. To have it queried only for Preview, for example, put an AppleScript in:

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

Download this example script file to see what you need to do in your AppleScript script:

The trick is that you need to implement this handler:

on getDefaultFolder(appName, dialogType, firstTime) 

which returns the location of the default folder. Open up the sample script file in Script Editor (or your AppleScript editor of choice) and have a look. I’ve tried to explain things clearly in the comment at the top, and the script shows a number of different ways of returning folders to Default Folder X. And of course, you can also use Jason’s complete script as a starting point.

I think Jason’s idea is great – it streamlines work on multiple projects, but most importantly, it reduces the chance for error as you’re trying to meet that pressing deadline. I’d love to hear how others use this feature, so please drop me a line if it works for you too!

Tags: , , , ,

6 Responses to “Default Folder X: Using AppleScript to specify default folders on the fly”

  1. […] dictionary to help scripters automate the handling of file dialogs (and don’t forget the scriptable default folders too). This version also adds support for the version of Path Finder distributed via […]

  2. neil thomas says:

    When I use โ‡งโŒ˜G in a save dialog, as part of a Keyboard Maestro macro, the navigation often hangs and the macro fails. I was wondering if it’s possible to tell DFX where to navigate to as part of a Keyboard Maestro macro, using applescript or some other means?

    • Jon says:

      Yes, it’s definitely possible. Default Folder X has a full complement of AppleScript commands. What you want is something like:

      set theFolder to POSIX file “/Applications/Utilities”
      tell application “Default Folder X”
      SwitchToFolder theFolder
      end tell

      • neil thomas says:

        Jon, I didn’t get a notification for this, so only just found it now. Fantastic!!!! Thankyou so much. ๐Ÿ™๐Ÿผ

        A further question, if you’ll indulge me…

        I’d love to be able to reopen recent Finder windows as you would browser tabs. I know you can use the following to return the folders recently accessed by DFX:

        tell application “Default Folder X”

        set theResult to GetRecentFolders

        end tell

        return theResult

        Do you happen to know of any way to get a list of folders recently accessed by Finder itself? Long shot, I know!

        You can see my attempts in this area here:

        • Jon says:

          What you want is:

          set theResult to GetRecentFinderWindows

          That will give you a list of the folders shown in recently closed Finder windows ๐Ÿ™‚ They’re listed with the most recent ones first, so just loop through that list to open however many recently visited folders you want, then you’re done!

Leave a Reply