Scripts quick access edit this
  • Author: Stephen Farrell <>
  • Authors (fixes): Dave Pearson <>, Matthew Hawkins <>
  • Version: 1.5
  • License: GNU GPL 2 or later
  • Downloads: services.jl, string2.jl

Synopsis Edit

Send mouse selection to shell program.

Description Edit

Send mouse selection to shell program -- similar to "Services" in NeXTSTEP. The idea is as follows: Say you want to look up a word in your dictionary program, but the current application doesn't know about the dictionary. Normally, this would require putting the selection in the clipboard, locating and launching the dictionary application, pasting the selection into the dictionary (if you're using X, good luck that it's still in your PRIMARY selection!), and finally telling the dictionary application to look up the word. With NeXTSTEP services, the dictionary could add a global keybinding that would act on the current selection. So "Command-=" would send the current selection to

services.jl is not as elegant as the NeXT design since it requires the user to set up the bindings and hook up the wiring to get the selection to the desired application. Sometimes this is trivial, but sometimes it is not. In particular, the example I give assumes you have one of those handy netscape launcher scripts that check if netscape is running and uses -remote if necessary. If you don't, get it... here's something that looks appropriate: (on FreeBSD, it's /usr/ports/www/netscape-wrapper).

Configuration Edit

To add actions, call services-add. The first argument is the entry that will appear in the menu, the second is the format of the shell command. All instances of '#' will be replaced with the selection. The final (optional) argument is some code to run on the selection to clean it up before sending it to the shell. I've defined a sample function, services-clean-for-browser, which does basic URL encoding, but you can insert your own function or lambda.

Sample usage:

put both waffle.jl and string2.jl in your load-path

 (require 'services)
 (services-add "Google" 
               "netscape ''" 
 (services-add "Google: I'm Feeling Lucky"  
               "netscape ''"  
 (services-add "Netscape" "netscape '#'" 
 (services-add "Dictionary" "xterm -T 'dict: #' -e dict #")
 (services-add "Unix man" "xterm -T 'man: #' -e sh -c 'man #; read'")  

NOTE: You must add some actions (as above) or else it won't do anything!

Of course you'll want a keybinding to activate services. I use C-M-SPC (bind-keys global-keymap "C-M-SPC" services) or else you can use the sawfish configuration GUI to set up the keybinding.

I've hacked up some string manipulation routines and use them as a separate library... I've included them inline in this package, but would be happy to contribute them to who/whatever is appropriate.

Community content is available under CC-BY-SA unless otherwise noted.