Stairways Software Icon

Stairways Software

Excellence In Software For Over Ten Years – Only with a Mac

Finder AppleScript "the selection" speed.

Keyboard Maestro includes a For Each action category to loop over the Finder’s selection. Usually the performance was OK, but occasionally I'd see horrendous performance. I tracked it down to the speed of this simply AppleScript:

tell app "Finder" to get the selection

In some cases it would take seconds or even tens of seconds per item returned (this seemed particularly bad in my Trash folder which has thousands of items - selecting even a dozen files could mean the AppleScript took a minute to run!

I comments on Twitter, and Takaaki Naganoya responded on Twitter to try "selection as alias list".

Boy was he right. The response to this:

tell app "Finder" to get the selection as alias list

is near instantaneous, every time. You get a slightly different result format for the results, but in all likelihood you'll get functionally the same behaviour at vastly improved speeds.

These results were on my Mac running 10.7.4 so it may be wise to verify the issue across a wider range, but since I cannot see any downside, this is the code I'll use in Keyboard Maestro in the future.

Posted Friday, June 22, 2012. Permalink. Post a Comment.


Post Comment

Name: (optional)
URL: (optional)
Email: (optional, not published)
CAPTCHA: two six three nine (required)
  To prove you are human, please enter the number as digits (ie, 1-9).
  You can use some HTML tags such as <b>, <i>, and <a href="">.
We reserve the right to remove any offensive or inappropriate comments.
Due to spam issues, comments are initially invisible until we review them,
you can see them (background red) and we can see them, but no one else.

Comment Preview

None yet.

Buy Now

User Database