
130
|
Chapter 5, KDE Desktop
#40 Create Your Own KDE Right-Click Menu Actions
HACK
Save this script to a file such as immail.sh and run it, like so:
foo@bar:~$ ./immail.sh bob
This script works by first making the command-line argument available as
the
$nick variable. After this, a while loop is started that uses grep to search
for the chosen nick in
$nick within the output of the reachableContacts
interface in KopeteIface. Nick is not online, so the process will just sleep for
10 seconds. When Nick does come online, an email is sent to you@foo.com
using the
mail command.
HACK
#40
Create Your Own KDE Right-Click
Menu Actions Hack #40
Create custom menu actions for when you right-click a file, directory, or
group of files and/or directories.
When you use KDE, do you ever find yourself having to click too many
times to do a simple operation, or resort to opening up a terminal to do a
task at the command line that should have been a no-brainer feature of
KDE? Now you can add your own features to KDE context menus. Right-
click a file and click Action
➝ Make Executable to make the file executable.
Right-click an empty space in a folder and click Action
➝ Create a new Bash
Script to open an editor and fill in the first line. This is a very cool hack
because you can create a context menu to launch scripts or programs writ-
ten in any language. It is especially powerful if you learn DCOP scripting
[Hack #39]. That way you can use the context menu selection to control KDE
programs.
Remember all the times you wrote a dandy new bash script and created an
icon to launch it, but when you clicked it, it didn’t run? Instead, it popped
up in an editor, because you forgot to make the script executable. With this
hack, you can create a script to make your file executable by right-clicking
its icon and selecting Actions
➝ Make file executable (see Figure 5-4). It
takes much less time than traditional methods.
All you have to do to create the context menu that will make a file execut-
able is create a text file formatted very much like an application link, and
then drop it in a special directory. We’ll start by creating a file called make_
executable.desktop. Start up your favorite editor, and enter the following
text:
[Desktop Entry]
Encoding=UTF-8
ServiceTypes=application/x-shellscript
Actions=MakeExe

Create Your Own KDE Right-Click Menu Actions #40
Chapter 5, KDE Desktop
|
131
HACK
[Desktop Action MakeExe]
Name=Make file executable
Exec=chmod +x %f
Icon=kfm
Save your work. The action this file takes is defined by the entry Exec=chmod
+x %f
. KDE substitutes the name of the selected file for %f. If you want to
make this feature available to everyone who uses KDE on this computer,
place the file here:
# cp make_executable.desktop <path to kde>/share/apps/konqueror/servicemenus
Depending on your Linux distribution, the path might not be tied to your
KDE directory. It might be /usr/share/apps/konqueror/servicemenus.
If you simply want to make this feature available to yourself, place the file
here (assuming your KDE settings are kept in ~/.kde; your distribution might
use ~/.kde3.3 or something similar):
$ cp make_executable.desktop ~/.kde/share/apps/konqueror/servicemenus
The ServiceTypes field in the file is set to the mime-type
application/x-shellscript, which means the menu option will
be available only when you right-click a shell script file.
Figure 5-4. Context-sensitive Actions menu
Get Linux Desktop Hacks now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.

