PerlPad [ Homepage | Project Summary page | Download | Source code ]
[ Back | Forward | Index ]

Registered functions, the Process Service and the dock menu

Using registered functions to process text quickly

Save your work

When I said persistent I meant that the definitions stay around while PerlPad is running. You shut it down, you lose.
This means you have to set up your work environment every time you start PerlPad. The best way to do this is to put the setup into the PerlPad startup file. Just create a new text file, put in the Perl code you want to run (like subroutine definitions) and save it as ~/Library/PerlPad/ This file will be automatically executed when PerlPad launches. You can just also manually execute (do in Perl-speak) any other file with

or by using the Do Perl Source File command in PerlPad's File menu.

Registered Functions

You might have noticed that there is a second Service offered by PerlPad: Process selection. In order to efficiently use this service, you need to declare some useful Perl snippets as registered functions. Let us register the functions we have seen so far.

register_function takes two arguments, the name for the button and the code that gets evaluated. If you made a mistake or want to change the function you can just re-register it under the same name.

Process selection with PerlPad

Now that we have three registered functions, how to use them? There are two ways, the first is the Process service. In any editable text area you can run the service on some selected text. PerlPad will show you a dialog asking which function you want to process that selection with (you can also type any other Perl snippet into that dialog). The result replaces the original selection, similar to the Evaluate service.

Process Pasteboard with the Dock Menu

You can not always use the Services Menu unfortunately: It only works in Cocoa apps (and some Carbon apps) and only in editable text areas. But PerlPad offers you a more universal alternative: it can also process the pasteboard. You can just copy the input text (Cmd-C) in any app (Cocoa, Carbon, Classic, Java...), select your registered function from the PerlPad dock menu and find the result in the pasteboard from where Cmd-V can put it anywhere you want.

Some examples

PerlPad can be useful for AOL users:

Timestamp the input:

A bigger pasteboard: Many people need the system pasteboard to store more than one entry. We can provide a simple solution with what we have learned so far:

  • You can now Process the selected text with make clip to copy it to the pasteboard and save it for later use.
  • You can retrieve the last clip with a normal Paste.
  • You can retrieve any clip by typing some text that appears in it (and preferably in no other clip) and Process it with get clip (you could also type get_clip 'search string' and Evaluate it).

This pasteboard only works with unformatted text (no images, no RTF) and is a little too uncomfortable for real use (you have to run the Process service, and then select the correct function get clip) but you can make these two functions appear in the service menu and assign keyboard shortcuts to them. Read on about Add-on services.

PerlPad [ Homepage | Project Summary page | Download | Source code ]
[ Back | Forward | Index ]
Built With WebMake Logo