Script-fu for arbitrary selectable text across applications. Possibilites?
February 25, 2006 7:16 PM   Subscribe

Script-fu for arbitary text: Across applications (but especially in text editors) I want to be able to (a) right click on a bit of selected text (b) have the usual contextual menu pop up upon doing so, but with options to (c) send said text to an arbitrary script (perl, python, whatever) and (d) potentially have the selected text replaced by script results, if the context is right. What are my best options for both the Mac and Windows?

I would settle for instructions on how to work this for a specific text editor -- Vim, Dreamweaver, TextPad, TextWrangler -- if they're easy or other options are unavailable, but being able to do this in any app where one can edit text (and heck, maybe even in some where you can't) would be great.
posted by namespan to Computers & Internet (9 answers total)
 
I'm relatively certain that this isn't possible in Windows because the context menu items are programmed into the individual applications and are not centrally available like the context menus when you right click a file or folder. I also doubt any of the editors you listed have an option within the app to customize the menus. If you were dealing with Word I think you'd probably be able to though. Someone correct me if I'm wrong
posted by saraswati at 8:26 PM on February 25, 2006


Response by poster: saraswati, I'm almost positive it's possible on Windows. On my machine, all kinds of extras (Edit with Vim, Archive with Rar, Edit with Fireworks, Edit with Altova XMLSpy, Google Search) are crammed into my right-click contextual menus. Though only some of the extras show up in various contexts.

And I swear somewhere on AskMe I've read about somebody doing this with Python scripts.
posted by namespan at 8:53 PM on February 25, 2006


as saraswati said, this isn't possible within applications- only in explorer, the windows file browser.
posted by wzcx at 9:28 PM on February 25, 2006


Response by poster: Hmm. You appear to be right. Bother.

Well, either it's the Mac for me, or something editor specific, I guess.
posted by namespan at 10:42 PM on February 25, 2006


Your best bet would be something like Macro Express. I'm not sure that you could insert it into the program's context menu (unless it allows for user-defined commands; some do) but it could certainly act on the selected text though a keystroke and do everything else you need.

Alternatively, the kitchen sink of editors can be programmed to do anything and everything.
posted by Rhomboid at 10:43 PM on February 25, 2006


Vim should have a command to run your selection through an arbitrary shell command. There's a how-to on doing this with console vi. No idea if it'll work from a context menu like you want, though--my vi experience is extremely limited.
posted by arto at 10:57 PM on February 25, 2006


Writing a context menu plugin on the mac that can act on any standard app's text field would definitely be possible, but beyond my abilities.

As for specific apps, it's trivial to do this in BBEdit; just write a perl or python script that does whatever transformation you're after and drop it in the app's script menu; that script can then be applied to the full document or to any selected block whenever you like. (As a regular menu item, not a right-click item, but you could bind a key to each script if you prefer.)
posted by ook at 8:20 AM on February 26, 2006


Big Cat Scripts for OS X can do what you're after if you can provide it a little AppleScript to wrap around a "do shell script" command.

It's sadly dead on Intel Macs and a brief mail exchange with Brent Simmons, the creator, revealed that he's not sure if it's going to make the move to a universal binary. Worked fine all the way up through 10.4.4 on a PPC Mac, though.

I put together something that did lookups on the BBEdit selection in Webopedia and turned the resulting URL into glossary entries. Might help get you started. No representations about its elegance or quality ... I was just noodling. I think there's a sample "Lookup the Selection in Google" in the Big Cat distribution to get you started, too.
posted by mph at 10:01 AM on February 26, 2006


I've used Nedit (on linux) to do just what you describe (well, the second thing at least). It runs on anything with x-windows installed, so it should be possible to use on both Mac and Windows. It appears there's even a windows port for you to look at. To get you started on Mac, here's the osx package page on SourceForge. Here's the manual page on adding custom shell functions.
posted by primer_dimer at 12:22 PM on February 26, 2006


« Older Where can I find a website that has clear workout...   |   Do inline water softeners work? Newer »
This thread is closed to new comments.