Discussion:
tiny dictionary-invoking bash script for KDE
Jonathan Hartley
2004-06-18 13:52:38 UTC
Permalink
Hi all. I'm new to the list and fairly new to London. Looking forward to my first GLLUG meet!

Inspired by an article in this month's Linux Format:

For anyone who runs KDE, this might be handy. Looks up the current selected word in kdict (if installed) or else invokes konqueror on dictionary.com. Assign it to a key press (eg. Alt-D) (which on KDE3.2.3 seems to mean you have to add the script to your start menu) and I've found it exceptionally handy!

Probably it should try and figure out the correct web-browser to use, instead of assuming konqueror exists. Any better ideas for that than searching a hard-coded list of possible browser executables?

Cheers,

Tartley

Jonathan Hartley
***@tartley.com
+44 (07903) 729 838
--
Gllug mailing list - ***@gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
Jonathan Hartley
2004-06-18 13:53:31 UTC
Permalink
And this time with the script:

Tartley

Jonathan Hartley
***@tartley.com
+44 (07903) 729 838


#!/bin/bash
#
# dict-lookup
#
# Look up the currently highlighted word in a dictionary.
# Uses kdict (an optional KDE component, from the package 'kdenetwork3-query')
# if it is installed, otherwise invokes konqueror on dictionary.com.
# Works for text selected from any application running on the KDE desktop.
#
# Assign this to a keyboard shortcut (Eg Alt-D) for maximum utility.
# On KDE3.2.3, you have to add it to the Start menu to do this.
#
# Jonathan Hartley, tartley.com, Jun 2004.
# Inspired by Nick Furness' similar Win32/IE widget of many years ago.

# define a URL used to look up dictionary entries
URL_LOOKUP="http://dictionary.com/search?q="

# get most recent text selection from any KDE desktop application
SELECTION=`dcop klipper klipper getClipboardHistoryItem 0`

# is kdict installed?
if [ -x "`which kdict 2>/dev/null`" ]; then
# kdict installed - so use it
kdict $SELECTION
else
# kdict not installed, use konqueror on dictionary.com
konqueror $URL_LOOKUP$SELECTION
fi
--
Gllug mailing list - ***@gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
Loading...