May 26, 2008

How-To: Make a Simple Amarok Script in Bash

Updated: May 26, 2008

Creating a simple Amarok script in Bash can be easily done using the DCOP interface. For example, a simplistic script which creates a text file with collection statistics would look like this:

#!/bin/bash

# CollectionStats 2 TXT - creates the file ~/amarok_collection.txt containing collection statistics

echo "AMAROK COLLECTION STATS" >~/amarok_collection.txt
echo "=======================" >>~/amarok_collection.txt

echo -n "ARTISTS: " >>~/amarok_collection.txt
dcop amarok collection totalArtists >>~/amarok_collection.txt

echo -n "ALBUMS: " >>~/amarok_collection.txt
dcop amarok collection totalAlbums >>~/amarok_collection.txt

echo -n "SONGS: " >>~/amarok_collection.txt
dcop amarok collection totalTracks >>~/amarok_collection.txt

echo -n "GENRES: " >>~/amarok_collection.txt
dcop amarok collection totalGenres >>~/amarok_collection.txt

To test it, copy it into a file of your choice, say ac2txt.sh, and make the file executable. Next, put it into a directory like amarok_collection2txt and compress it using gzip. To be able to install it from Amarok, append '.amarokscript' after the script's name, so your compressed file will have the name 'amarok_collection2txt.amarokscript.tar.gz'.

Next, open Amarok, go to Tools -> Script Manager and click on the 'Install Script' button, then run it. A file with the name amarok_collection.txt should be generated inside your home directory, which will look something like this:

AMAROK COLLECTION STATS
=======================
ARTISTS: 403
ALBUMS: 251
SONGS: 3810
GENRES: 11

No comments: