Hi,

How can I write OS X Services in Perl? For instance, if I'm editing a new message in Mail.app, I'd like to highlight some text, then invoke a service to transform each line by a regular expression. Anyone know the options for creating new Services?

Maybe PerlPad does what you want?

http://perl-pad.sourceforge.net/

just as Dan suggested, PerlPad certainly does what you want.


As the author, I feel I have to advertise it a little more, so please excuse the commercials below :-)
I have recently released version 0.2 and invite everyone to give it a try.


PerlPad allows you to process the selected data with Perl code via Services.
It also makes use of Add-On Services, allowing you to add your own Services very easily (for example the regex you mentioned).
Basically, you only have to put your Perl code into an XML service definition file and it will work. PerlPad takes care of hooking things together.
There are examples for this on the website.


But you do not really have to run the trouble of defining your perl code beforehand at all if you can write it ad hoc.
In your example, you would just prepend the text you want to transform with the regex or code you want (right in Mail.app), select it and run the PerlPad service.


For example:

uc
__DATA__
here goes your text that will be upper-cased.

Select this, run the service. Works in Mail.app just fine.

#! perlpad -n
printf '%5d>%s', $. , $_
__DATA__
here goes your text
whose lines will be numbered

So please give PerlPad a try.
If you want to implement your own Services completely stand-alone (without PerlPad) have a look at CamelBones.
This framework allows you to write Cocoa apps (like Services) in Perl.
You need it anyway to install PerlPad :-)



Cheers,


Thilo







Reply via email to