(archive 'newLISPer)

January 30, 2009

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

Filed under: newLISP — newlisper @ 22:47
Tags:

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 
[text]
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
rslt
[/text])

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

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

/usr/share/newlisp/guiserver.jar
/usr/share/newlisp/newLISP128.png
/usr/share/newlisp/modules/cgi.lsp
/usr/share/newlisp/util/newlisp.vim  

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

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: