How-to: Use Butler and AppleScript to open a folder

I know what you’re thinking…how hard can it be to open a folder? Not very hard at all. But what I wanted was a way to open a certain folder with a certain view and sort order, even though I may then change that folder’s view and sort order, thereby messing up future openings of that same folder. In my case, I wanted my Downloads folder to open, at a given size and location, sorted in reverse date order. Moom can do 90% of this using saved window layouts, but it can’t do anything with the actual Finder window, such as setting the view and sort column.

After a bit of work with AppleScript, I came up with a solution that got me everything I wanted. By storing the AppleScript in Butler, I can now open my folder with the press of a hot key, at any time from any application. Here’s how I did it.

First, open Butler’s settings window, and click on the Configuration tab. Click the plus sign at the bottom left corner of the window, select Smart Item > AppleScript > AppleScript:

Once this item has been added to Butler’s configuration, you’ll need to decide where you want it: visible within one of the Menu Bar areas, or as a Hidden item that you’ll activate only via the keyboard and/or mouse. I keep mine in the Hidden section, but you can drag the entry wherever you’d like to use it.

Next, create the AppleScript. Click on your newly-added action in the left-hand pane of Butler’s configuration window, and then click on the Source Code tab on the right. While you’re here, click on the box at the top and name your action (Open Downloads Folder or whatever); make sure you press Tab when done so the change is saved. In the Source Code area, paste the following code:

tell application “Finder”
  set myWindow to make Finder window to folder “path:to:folder:to:open”
  set current view of myWindow to list view
  set the sort column of the list view options of myWindow to the modification date column
  activate
end tell

You’ll need to replace path:to:folder:to:open with the path to the folder you wish to open. The path starts at the root of the hard drive for local folders; if the folder is on a networked volume, start with the name of the mounted drive. You can also modify the view settings; you don’t have to use list view sorted by date modified. Here are the options available for each:

  • Current view: icon view, list view, column view, group view, flow view
  • Sort column: name column, modification date column, creation date column, size column, kind column, label column, version column, comment column

You should probably test your code in AppleScript editor prior to pasting into Butler; it’s much easier to test there. Once it’s all working, paste it into Butler’s Source Code tab, then click over to the Triggers tab. Assign a Hot Key of your choice, and/or a hot corner to use to activate your AppleScript.

Once you’ve done that, you’re good to go. Press your trigger or move to your hot corner, and your script will trigger. In my case, it takes a couple seconds to run, as I’m opening a folder on a networked drive. But even with this delay, pressing a hot key beats navigating to Finder and then opening and customizing the window again.

One Response to “How-to: Use Butler and AppleScript to open a folder”

  1. mpmchugh says:

    Thanks for the tip. It gave me the idea of using Butler for a tandem window script I’ve been using for years, but had always launched via DragThing. I had never noticed Butler’s Applescript capabilities.

    The mind reels with the future possible integration between Moom and Butler 5.

    Someday, perhaps… :-)

    -mpm