ZipPlayer Plays Music Archive: Part 2

by Daniel Meiß-Wilhelm (Leiche)

In the May issue of The NEW PCLinuxOS Magazine, we learn to create a script to open a zip archive to listen to the music files inside with xmms.

Before we get started, I need to update the previous article: I forgot to close this line:

SAVE=$(kdialog --title "zip-player" --getopenfilename "open…"

The corrected line is:

SAVE=$(kdialog --title "zip-player" --getopenfilename "open…")

Now we want create a servicemenu for KDE 4.

What Is A Servicemenu?

A servicemenu is an entry on the right click menu, and is used to help to start some apps easier, and to perform special functions on certain files.

When you want to add a servicemenu only for you, just save a text document in this directory:
/home/<user>/.kde4/share/kde4/services/ServiceMenus/.

If you want the servicemenu to be available to all users, then save the text document in the /usr/share/kde4/services/ServiceMenus/ directory. The document should be saved as zip_player.desktop.

What should we put in the document?

When we open a another .desktop file, such as the dropbox.desktop file, with Kwrite, we get:

pic

So, the right click menu shows:

pic

In the first line, we find [Desktop Entry] as the heading, and under that, we find the following:

Type=Service
ServiceTypes=KonqPopupMenu/Plugin
MimeType=all/all;
Actions=getPublicURL;copyPublicURL;
X-KDE-Submenu=Dropbox
X-KDE-StartupNotify=false
X-KDE-Priority=TopLevel

We must first change some entries:

Type=Service
Name=Zip_Player
Encoding=UTF-8
ServiceTypes=application/zip
Actions=zip_player
X-KDE-ServiceTypes=KonqPopupMenu/Plugin
MimeType=all/allfiles;

Notice: There is not a specific order for the sequence of entries.

We do not need all entries, so we removed X-KDE-Submenu=Dropbox, since we have only one entry in our servicemenu. X-KDE-Priority=TopLevel is not needed, either. The ServiceTypes have we specified as application/zip. Also we add Encoding=UTF-8. By MimeType=all/allfiles; it will be displayed by all files in the right click menu. And the line Actions=zip_player, provides the name for the next entry line.

[Desktop Action zip_player]
Name=Zip Player
GenericName=Zip_Player
Exec=zip_player
Icon=xmms.png

In the header we read Desktop Action zip_player, the action for the Servicemenu (right click menu).

Name=Zip Player displays the name Zip Player in our pop up service menu in KDE 4.

GenericName=Zip_Player is not needed, and will not displayed on the desktop.

Exec=zip_player specifies the executable program. (It's always in /usr/bin, not in /bin, so you must give the directory to the program as /home/USER/documente/zip_player).

Icon=xmms.png displayed a icon in the right click menu.

If you saved it in your home directory
.kde4/share/kde4/services/ServiceMenus/, and you click now with the right mouse button on a ziparchive, it's displayed as your new created Servicemenu under "Action > Zip Player". Feel free to click it, but what does it do?

Why open the file browser?

It should open the archive with xmms, and not the open file browser. Also we must change some lines in our script, so let us do it. Open the script with Kwrite:

#!/bin/bash
#
mkdir $HOME/.zplayer
SAVE=$(kdialog --title "zip-player" --getopenfilename "open…"
unzip $SAVE -d $HOME/.zplayer && xmms $HOME/.zplayer && rm -fr $HOME/.zplayer  | exit

At first (I forgot it) we add Encoding=UTF-8, so will correct set the font.

#!/bin/bash
#
Encoding=UTF-8
mkdir $HOME/.zplayer
SAVE=$(kdialog --title "zip-player" --getopenfilename "open…" )
unzip $SAVE -d $HOME/.zplayer && xmms $HOME/.zplayer && rm -fr $HOME/.zplayer  | exit

But now, we need a FileOpenParameter as function. So, we add the following lines:

usage ()
{
echo "No File"
exit 1
}
#
if [ $# -eq 0 ];
then
usage
fi
#
FileOpenParameter="$1"
#

and remove the line

SAVE=$(kdialog --title "zip-player" --getopenfilename "open…" )

In the next line, we change $SAVE in "$FileOpenParameter".

Our script shows now:

Encoding=UTF-8
#Funktion
usage ()
{
echo "No File"
exit 1 #Beendet Script
}
#
if [ $# -eq 0 ];
then
usage
fi
#
FileOpenParameter="$1"
#
if [ ! -d $HOME/.zplayer ]; then
mkdir $HOME/.zplayer
fi
#Archiv entpacken in Ordner, öffnen mit xmms, nach Beendigung Ordner löschen.
unzip  "$FileOpenParameter" -d "$HOME/.zplayer" && xmms $HOME/.zplayer && rm -fr $HOME/.zplayer | exit
#
exit 0
pic

Save it and try again to open a zip archive with Zip Player. It should now be working.