(archive 'newLISPer)

January 4, 2006

newLISP and the Mac Finder working together with Big Cat

Filed under: newLISP — newlisper @ 15:35
Tags:

>

It’s useful to be able to run newLISP scripts when you’re using the MacOS Finder. The best way I’ve found to do this is a free utility called Big Cat, written by Brent Simmons, ace Mac programmer and developer of NetNewsWire. Big Cat provides you with the ability to choose and run scripts from the Finder’s contextual menu.

When you’ve installed it, put the scripts that you want to run in the ~/Library/Application Support/Big Cat Scripts/Files folder. They’ll be available in the Finder when you’ve selected one or more files.

The basic form for a Big Cat script is something like this:

#!/usr/bin/newlisp
;;; change files to have a+x execution permissions
(set 'file-list (rest (rest (main-args)))) ; get selected files
(dolist (i file-list)                   ; with each file in argument
    (set 'f (format "'%s'" i))      ; quote the filename to protect it
    (exec (string "chmod a+x " f)))
(exit)

This tries to change the file’s execute permissions. I use this in the Finder after I’ve written a newLISP script (or a shell script) in a text editor. The first line skips the first two arguments, then uses the remaining arguments as file names for the dolist loop.

While you’re testing your Big Cat scripts, it’s useful to keep the Console application running, showing the console.log – errors and standard output are written here.

Another script I use a lot is this one:

#!/usr/bin/newlisp
;;; copy unix paths to clipboard
(set 'file-list (rest (rest (main-args))))
(set 'clipboard-contents nil)
(dolist (i file-list)
    (set 'f (format "'%s'" i))
    (push f clipboard-contents))
(exec (string "echo " (join clipboard-contents " " ) " | pbcopy "))
(exit)

This copies the Unix paths of selected files to the system clipboard, ready for being pasted in to another application. I use this because not all applications support the Option-Drag technique for inserting the pathnames of Unix files visible in the Finder. The pbcopy command (and its pbpaste counterpart) are Unix commands for reading and writing to the pasteboard, which is the same as the clipboard. It can be a useful way of making information available to GUI applications that don’t communicate with the Unix engine room.

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

Create a free website or blog at WordPress.com.

%d bloggers like this: