debian Impostare lo stato ed il messaggio di stato di Pidgin con uno scriptfedora Impostare lo stato ed il messaggio di stato di Pidgin con uno scriptbsd Impostare lo stato ed il messaggio di stato di Pidgin con uno scriptlinux Impostare lo stato ed il messaggio di stato di Pidgin con uno scriptubuntu Impostare lo stato ed il messaggio di stato di Pidgin con uno scriptImpostare lo stato ed il messaggio di stato di Pidgin con uno script

Di Emanuele Cipolla | Nov 15, 2008
Stampa questo post Stampa questo post Articolo originale

Questo post è più un appunto che un vero HOWTO. Con lo script di cui presento il codice è possibile ottenere degli aggiornamenti mirati del messaggio di stato (e dello stato stesso) in occasione di eventi prestabiliti, ad esempio la riproduzione di un file multimediale. Per accostarvi allo scenario potete pensarlo come una versione un po’ più rozza dei plugin che, in altri programmi di messaggistica istantanea, prelevano il titolo della canzone in riproduzione da un player.

L’utilizzo di uno script esterno permette ad applicazioni che non dispongono naturalmente di una tale capacità (come il mio attuale player audio, Audacious) di cambiare il messaggio di stato di Pidgin.

Perchè tutto funzioni correttamente, è necessario che DBUS sia attivato e supportato dalla vostra copia di Pidgin. Ecco il sorgente dello script

#!/bin/bash
APPNAME=$(basename $0)
PARAMETERS="$2 $3 $4 $5 $6 $7 $8 $9"

GREP=$(which grep)
AWK=$(which awk)
SED=$(which sed)
ECHO=$(which echo)
PURPLE_REMOTE=$(which purple-remote)
PURPLE_SEND=$(which purple-send)
PS=$(which ps)
CAT=$(which cat)
RM=$(which rm)

CURRENT_STATUS=$($PURPLE_REMOTE getstatus)
TEMPFILE_STATUS_MESSAGE=$HOME/$APPNAME.dbus-$($PS ax | $GREP -m1 "dbus-daemon" | $AWK '{ print $1 }').status-message
TEMPFILE_STATUS=$HOME/$APPNAME.dbus-$($PS ax | $GREP -m1 "dbus-daemon" | $AWK '{ print $1}').status

case "$1" in

"--backup-status" )
	if [ -f $TEMPFILE_STATUS ]; then
		$RM $TEMPFILE_STATUS
	fi
	$ECHO $CURRENT_STATUS >> $TEMPFILE_STATUS
	;;

"--backup-status-message" )
	if [ -f $TEMPFILE_STATUS_MESSAGE ]; then
		$RM $TEMPFILE_STATUS_MESSAGE
	fi
	CURRENT_STATUS_ID=$($PURPLE_SEND PurpleSavedstatusGetCurrent | $GREP int32 | $AWK '{ print $2 }')
	CURRENT_STATUS_MESSAGE=$($PURPLE_SEND PurpleSavedstatusGetMessage int32:$CURRENT_STATUS_ID | $GREP string | $SED -e "s/string//g" -e "s/\"//g" -e "s/    //g")
	$ECHO $CURRENT_STATUS_MESSAGE >> $TEMPFILE_STATUS_MESSAGE
	;;

"--set-status" )
	$PURPLE_REMOTE setstatus?status="$2"
	;;

"--set-status-message" )
	$PURPLE_REMOTE setstatus?status=$CURRENT_STATUS\&message="$PARAMETERS"
	;;

"--safe-set-status" )
	if [ ! -f $TEMPFILE_STATUS ]; then
		$0 --backup-status
	fi
	$0 --set-status $2
	;;

"--safe-set-status-message" )
	if [ ! -f $TEMPFILE_STATUS_MESSAGE ]; then
		$0 --backup-status-message
	fi
	$0 --set-status-message $PARAMETERS
	;;

"--clear-status" )
	$0 --set-status ""
	;;

"--clear-status-message" )
	$0 --set-status-message ""
	;;

"--restore-status" )
	OLD_STATUS=$($CAT $TEMPFILE_STATUS)
	$0 --set-status "$OLD_STATUS"
	if [ -f $TEMPFILE_STATUS ]; then
		$RM $TEMPFILE_STATUS
	fi
	;;

"--restore-status-message" )
	OLD_STATUS_MESSAGE=$($CAT $TEMPFILE_STATUS_MESSAGE)
	$0 --set-status-message "$OLD_STATUS_MESSAGE"
	if [ -f $TEMPFILE_STATUS_MESSAGE ]; then
		$RM $TEMPFILE_STATUS_MESSAGE
	fi
	;;

*)
	$ECHO "$APPNAME: Wraps itself around the Pidgin command line utilities to (re)set, backup and restore"
	$ECHO "the status message."
	$ECHO ""
	$ECHO "Hacked together by Emanuele Cipolla <bugs @emanuelecipolla.net>, 2008."
	$ECHO "This script is released into the public domain."
	$ECHO ""
	$ECHO "WARNING: You _have to_ use a single option per run, no verification or simultaneous execution"
	$ECHO "is made."
	$ECHO ""
	$ECHO "SYNOPSIS: $APPNAME [--backup-status]"
	$ECHO "[--backup-status-message]"
	$ECHO "[--set-status] [[status]]"
	$ECHO "[--set-status-message] [[message]] [[...]]"
	$ECHO "[--clear-status]"
	$ECHO "[--clear-status-message]"
	$ECHO "[--restore-status]"
	$ECHO "[--restore-status-message]"
	$ECHO ""
	$ECHO "--backup-status                 Backups the current status to $TEMPFILE_STATUS."
	$ECHO "--backup-status-message         Backups the current status message to $TEMPFILE_STATUS_MESSAGE."
	$ECHO "--set-status                    Sets the status."
	$ECHO "--set-status-message            Sets the status message."
	$ECHO "--safe-set-status               Sets the status after backing up the old one."
	$ECHO "--safe-set-status-message       Sets the status message after backing up the old one."
	$ECHO "--clear-status                  Resets status to \"Online\"."
	$ECHO "--clear-status-message          Sets a blank status message."
	$ECHO "--restore-status		Restores back the status from $TEMPFILE_STATUS."
	$ECHO "--restore-status-message        Restores back the status message from $TEMPFILE_STATUS_MESSAGE."
	;;
esac

Ecco, invece, come si presenta Audacious dopo essere stato configurato per l’utilizzo dello script, in seguito all’attivazione del plugin Song Change:

Lo screenshot è stato ritagliato, ma il comportamento dell'applicazione è quello

Lo screenshot è stato ritagliato

Enjoy.

Posted in AAC, Applicazioni, Debian, DragonFlyBSD, Fedora, FreeBSD, Gaim, GNU/Linux, Informatica, Licenze, M4A, Mac OS X, MP3, Multimedia, NetBSD, OGG, Pidgin, Programmazione, Shell scripting, Slackware, Theora, Ubuntu, Vorbis   Tagged: awk, grep, linux, message, messaggio, rm, script, sed, stato, status, text, util   
Tags: Debian, Fedora, FreeBSD, Linux, Ubuntu

Post correlati

Lascia un commento

Se vuoi inserire un commento, per favore completa il form sottostante.

Nome (obbligatorio)

Email (obbligatorio)

Sito Web

Commenti

© 2008 - 2009 Tuttolinux - novità ed articoli dal mondo del pinguino !
Tutti i contenuti © dei rispettivi autori. Leggi questo per ulteriori informazioni.
Creative Commons LicenseIl contenuto di questo sito web è pubblicato sotto una Licenza Creative Commons.

Warning: stristr() [function.stristr]: Empty delimiter in /home/.nine/luckylinux/tutto-linux.com/wp-content/plugins/wassup/wassup.php on line 2093