Use pbcopy to direct stdout to osascript

Nov 27, '03 11:50:00AM

Contributed by: Anonymous

A serious drawback to the command-line osascript tool is that it doesn't provide a way to pass arguments to a script. A workaround is to use the clipboard to store data (via pbcopy), then retrieve it from AppleScript's the clipboard object. For example:


echo 'Test text' | pbcopy; osascript -e 'tell application 
 "Finder"' -e 'activate' -e 'set theMessage to the clipboard' 
 -e 'display dialog theMessage buttons "OK" default button 1'
 -e 'end tell'
 
The above is one long line; replace each line break with a single space when copying and pasting. You can substitute any command (or series of piped commands) for echo 'Test text'.

Comments (3)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2003111916263473