gtk dialogs in linux

Wednesday, December 05, 2007

Bash scripts are fantastic. I could end the post there, but they can be made even better for end users by using one of the simple GUI applications out there that can be run from bash. Here's a great little example (using gtkdialog)that pretties-up the interface for my infrared phone script from this post.

#! /bin/bash

OUTPUT=$(/usr/local/bin/phone-connect $1 | sed -e 's/\(.*\)$/


Beautiful

get connected with infrared device in linux

Using Ubuntu (known to work for Feisty and Gutsy), follow the instructions here. The only change to those instructions I needed to make was to set automatic="true' in irda-utils.

Then use the following script:

#! /bin/bash

# phone-connect. Copyright Brad Milne, 2007. Search for infrared phone
# and mount it using obexfs if available.

case "$1" in
start)
echo -n "Starting connection to phone..."

#first restart irda-utils if phone not visible
grep nickname /proc/net/irda/discovery > /dev/null
if [ $? -eq 0 ]; then
/etc/init.d/irda-utils restart > /dev/null
fi
obexfs -i /mnt/phone

if [ $? -eq 0 ]; then
PHONE=$(grep nickname /proc/net/irda/discovery | sed -e 's/nickname: //' | cut -d, -f1)
echo "Connected to $PHONE"
else
echo "Connection failed. Does phone have infrared turned on?"
fi
;;
stop)
# 'stop' I haven't yet been able to implement due to restrictions
# on unmounting the fuse device. For now I use 'sudo umount /mnt/phone'
echo -n "Stopping connection to phone..."
/bin/fusermount -u /mnt/phone/
if [ $? -eq 0 ]; then
echo "Done"
else
echo "Failed. Was it connected?"
fi
;;
status)
ifconfig irda0 | grep irda0 > /dev/null
if [ $? -eq 0 ]; then
echo "Infrared device is active"

grep nickname /proc/net/irda/discovery > /dev/null
if [ $? -eq 0 ]; then
PHONE=$(grep nickname /proc/net/irda/discovery | sed -e 's/nickname: //' | cut -d, -f1)
echo "Currently connected to phone"

if [ $(ls -l /mnt/phone | wc -l) -gt 1 ]; then
echo "Phone files accessible at /mnt/phone"
else
echo "Phone not mounted"
fi
else
echo "Not connected to phone"
fi
else
echo "Infrared device not active. Is infrared device plugged in?"
fi
;;
*)
echo "Usage: phone-connect {start|stop|status}"
;;
esac


Then to make it runnable by any user, do a chmod 4711 as described here, on the script itself, obexfs, irda-utils, and on fusermount (which needs to be readable by all users also).