The default behaviour
The KDE device notifier is a widget that can be used to managed plugged-in devices like e.g. usb pen-drives. In a default Kubuntu installation this is shown as an icon in the taskbar. When clicking on it it shows e.g. all partitions of plugged in devices.
When you click on a partition it offers a couple of actions that can be started for that particular partition (e.g. downloading pictures to digikam or open the drive in dolphin).
Why I needed an additional action
A task I have to do every day is to move downloaded podcast on a usb pen-drive, so I listen to the podcasts on my car radio. In the beginning I moved the files manually to the drive and then I wrote a script that did this job for me.
The Script created a directory in the format ddmmyyyy (e.g. /media/disk/05112009) on the pen-drive and moved the files in there. Afterwards it did a sync to ensure that all data had been flushed to the drive.
As I always used the device notifier to mount the drive, I wanted to have my script as an action in there.
Where do I find the actions in the filesystem?
The actions of the device notifier are placed in the directory /usr/share/kde4/apps/solid/actions. There is one file for each action.
Custom actions for a specific user can be placed in ~/.kde/share/apps/solid/.
There are a couple of paramterers that describe the action e.g.:
- X-KDE-Solid-Predicate determines for which devices the action should be available
- Name is the label of the action shown in the device notifier
- Exec is the command that will be executed.
There are some variables that can be passed to the exec-command (there might be more):
- %f gives StorageAccess.filePath
- %d gives Block.device
- %i gives UDI
Adding an action to device notifier
To execute my mp3 moving script I created the file /usr/share/kde4/apps/solid/actions/movemp3.desktop:
X-KDE-Solid-Predicate=[[ StorageVolume.ignored == false AND StorageVolume.usage == ‘FileSystem’ ] OR [ IS StorageAccess AND StorageDrive.driveType == ‘Floppy’ ]]
[Desktop Action open]
Name=Move MP3 files
After restarting KDE the device notifier now contains a new entry:
Formerly I started the script from the terminal, but now I start it from the gui. Therefor I added some gui interaction to the script to make it more comfortable:
Just in case anyone is interested in the simple script:
kdialog –yesno “Move MP3-files to drive ($newpath)?”
if [ “$ret” -eq “0” ]
kdialog –yesno “Delete old files? ( `ls $path/[0-9][0-9][0-9][0-9][0-9][0-9]` )”
if [ “$?” -eq “0” ]
rm -r $path/[0-9][0-9][0-9][0-9][0-9][0-9]
mkdir -p $newpath
mv $mp3path/*mp3 $newpath/
kdialog –msgbox “Files were moved, you may now disconnect the drive by device notifier!”
kdialog –msgbox “cancelled…”