It is truly amazing just how much of what we use, from big ideas to little ones, was invented in the 1960s.
What is the difference between OSX services and Unix pipes ? Could something like OSX services be built trivially on Linux ?
If I ask about how a OSX-like services framework may be created, what is the answer ? For example, there are OSX services that remove spaces from text or even summarize paragraphs.
IMHO, some of them are contextual - some services only show up as active when you copy a URL, etc.
They seem pretty nifty and I always wondered why Linux doesnt have something like this.
Furthermore, Linux doesn't have them because, unlike pipes, this isn't a feature that should be provided by kernels. If you wanted to add them to Gnome or KDE, I'm sure you could with minimal trouble.
UNIX pipes are only a tiny bit like OS X Services from a user's perspective. They are nothing alike from a program's perspective.
As others have said, UNIX pipes simply connect one program's standard output to another program's standard input. That's all. It uses the exact same mechanism that would otherwise show information to you and accept input from you.
OS X Services are a completely different, proprietary thing. It works via the 'Pasteboard' which is rather like a secondary clipboard. Apple created a specific interface which must be recognized by a program in order to supply OS X Services with data. This interface is wholly unrelated to the rest of the program's interfaces.
OS X Services are much more akin to something that you would build on Windows using COM, like a Windows Explorer Shell Extension.
If you wanted to recreate OS X Services on Linux, you would have to define some sort of new interface for exchanging data between applications, then convince developers around the world to add the new API into their programs.
FYI - My question changed from the similarity of pipes and services to just thinking about how something like services could be implemented on Linux. I did take a look at GnuStep Services, but is it the way someone would have done, if starting from a clean slate ?
Powershell has a "pipeline" as well which works at object level. Again, it may not be the same thing as pipes or services implementation-wise, but it is conceptually relevant.
Kinda funny concept anyway...
The requirement is that this be an executable script which can take any number of command-line arguments describing email headers, and which receives the body of an email on STDIN. I think this can all be done via pipes but I'm not entirely sure how - the trick is that the output of the program over STDOUT needs to be the concatenation of formatted command-line arguments plus the contents of STDIN. I had difficulty figuring out how to have two different commands both send output, in order, to the STDIN of `msmtp -t`. msmtp is configured to send email via a Google Apps account.
Here's what I'm using at the moment. It works but I think it could be more elegant and UNIXY without the temporary file.
T=`/opt/bin/mktemp` # create a temporary file
echo -e "From:$1\nTo:$2\nSubject:$3\n" > $T # format command-line args into the file
cat <&0 >>$T # append STDIN to the file
msmtp -t <$T # mail the file (-t parses the smtp recipient from the email headers)
rm $T # delete the file
# used as follows:
#/usr/local/bin/minimail "firstname.lastname@example.org" "email@example.com" "Subject of the Email" <body.txt
Sorry for the noise.