You should be automatically redirected . If not, visit
and update your bookmarks.


Process Finder Selection: the return of AppleScript (for a few seconds at least)

I recently wanted to process a group of files that had been selected in the MacOS X Finder. (This is a Mac-specific post!) Obviously I wanted to do the work with newLISP. Here's a three-step reminder of how to do it.

First, enable the Script icon on the menubar, if it isn't already. (Many people have described how to do this; here's a good one.) The Script Menu shows both global scripts and the scripts that are designed for the application you’re running. Scripts to be run in the Finder should be in /Users/you/Library/Scripts/Applications/Finder/. You don’t have to use a special suffix for the file.

Secondly, save the Finder-related scripts in that folder, and don’t forget to make them executable first! Here's the basic idea:

#!/usr/bin/env newlisp

(set 'applescript 
set rslt to {}
tell application "Finder"
  set s to selection
  repeat with i in s
    set end of rslt to (POSIX path of (i as alias))
  end repeat
end tell
[ /text])

(set 'file-list (parse 
      (exec (string "osascript -e '" applescript "'" ))) ", "))

(dolist (f file-list)   
  (println f))
; printed output goes to the console


Finally, enjoy working in newLISP rather than AppleScript! :)


Post a Comment

Links to this post:

Create a Link

<< Home