ftp.nice.ch/pub/next/developer/objc/services/Piper.README

This is the README for Piper.1.2.N.bs.tar.gz [Download] [Browse] [Up]

Piper

Piper is a Service that provides applications with
the ability to pass the current selection to a user
defined shell script. It appears in an applications
Services menu and has a submenu that lets the user
pick the script they want to run. The resulting output is either returned to the calling app or placed on the selection pasteboard.

Selection Types

Two types of selection may be passed to Piper: ascii
data or a filename. Piper runs the script in different ways according to the selection type. If the selection type is ascii data (eg if you make a selection in Edit), the selected data is piped to the script as standard input. If the selection is a file name (eg the current file in workspace manager), Piper will execute the script with the selected file name passed as a parameter.

Output

If the selection was a filename, the output from the script is placed by Piper on the selection pasteboard. From there it may be pasted into a document in the normal way.

If the selection was ascii data, the default action is also to place the output of the script on the pasteboard. However, if the script options file (see below) specifies a return type and if the calling application supports returned ascii data, the script output will replace the users selection.

Piper also has a Window that may be used to display the output from the script. The output in this window may be cut and pasted in the usual way. To display this window, select the Window... menu item. A preferences option specifies whether or not the window is cleared before running a script.

Parameter

Piper can pass an optional parameter to the script. If you select the Parameter... menu item a text field panel is displayed in which the user can enter a parameter. This is passed as the first parameter to the script. If the selection is a file name, that will then become the second parameter passed. A preferences option specifies whether or not this parameter field is cleared after running a script.

Loading Scripts

Piper looks for scripts in the users ~/Library/Piper directory. Each script must reside in a directory of its own and the name of the directory appears in Pipers submenu. The actual script (which must be executable) must be called script. If a new script is added, Piper must be informed. Do this by selecting the Reload Scripts menu item. This is necessary, because the list of scripts is stored in a section of Pipers executable which is examined by the workspace manager at login time.

Note: for this reason, Piper cannot be shared! It must reside in the users ~/Apps directory.

Options

A file called options may also be present in the script directory. This may have two possible lines:
	Return Type: NXAsciiPboardType
means that the script wants to return data to replace the users selection, rather than the default of placing on the pasteboard.
	Key Equivalent: K
means that K (for example) is the key equivalent for this script.

Examples

1)	awk '{print">"$0}'

This script will just prepend ">" to every line in the selection. Coupled with an options file specifying a return type, this could be used to quote sections of text in Mail.

2)	tar tvf $1

Simply lists the given tar file. Output may be viewed in Pipers window.

Author

This program was written by Dave Griffiths of Primitive Software Ltd. It's free. Hope you like it.
Please send bug reports and suggestions to:
	prim!dave@germany.eu.net
	
Acknowledgement

Last, but not least, it was Anthony Berno's idea! From a suggestion he made on comp.sys.next. Here is his original news article:

From: aberno@godel.questor.wimsey.bc.ca (Anthony Berno)
Newsgroups: comp.sys.next.misc,comp.sys.next.programmer
Subject: Really useful utility.
Date: 14 Apr 92 02:10:06 GMT

I'm always full of ideas, but rarely have enough time to even begin on  
them all. This time, though, there is something that would be so useful  
that I figured I should share it. I'd do it myself, as it would be really  
easy, but unfortunately I am desperately pressed for programming time for  
the next five months.

The idea is this: a Services-only application, which I have dubbed "Peter  
Piper". It would take a selection and pass it through a UNIX pipe, just  
like in Edit, except it would work with any application. There would be  
access to the pasteboard. The things I would use it for are:

1) Quoting messages in Mail, a la MailHelper
2) Passing things through awk so that I could get, say, only the 3rd  
column in a whole tab-separated array of numbers
3) Appending something to my quotes file automatically
4) Non-text stuff?? Image processing?? Adding stuff to a sound database?  
Who knows?

That's just off the top of my head. It would make use of a file in my home  
directory, called something like .peterpiperc, to get the things to add to  
the menu.

I really would like to see this, as it would make my NeXT about, oh, maybe  
a zillion times more useful. I just can't do it until August at least.  
Really, it would only take about a day.

Maybe I'll do it anyway. But the idea is here, you don't even have to give  
me credit. Just do it! :-)

-Anthony

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.