Feeds:
Posts
Comments

Posts Tagged ‘bash’

On our last party, I started using my old webcam to make a picture every 5 minutes to document the fun we were having. I used camorama, which has a build in feature to do exactly that.

Today I wanted to do the same with the webcam on my girlfriends netbook. UNR comes with Cheese, which does not have the ability to take pictures in regular intervals, but it worked out  of the box. I installed camorama, but for some reason it did not work.

After some debugging it still didn’t work so I though: this is Linux, there must be an easy hack to make Cheese take pictures automatically, and there is:

cheese& while true; do xvkbd -text " "; sleep 300; done

Running this in bash/a terminal will start Cheese and then simulate pressing the space key every 5 minutes. And Space is the shortcut for Take a photo. Of course you can’t do anything else on the netbook while this is running since Cheese has to be focused for this to work (There probably is a hack to fix that too).

Linux rocks!

Advertisements

Read Full Post »

Semiautostart

I always had the problem that I couldn’t decide if I should use autostart to start things like kmail and kopete. On the one hand I don’t want to start 10 apps manually at 7am but on the other hand I really hate that everything autostarts in other situations like restarting KDE because of debugging my X11 config.

So finally I found a good solution (which is also desktop environment independent):

#!/bin/bash
if kdialog --yesno "Autostart?"
then
  echo "Autostarting"
  kmail
  akregator --hide-mainwindow
  kopete
  basket --start-hidden
  gmpc&
  skype&
fi

I start this script with the normal autostart routine of KDE, an now I’ve got a simple popup asking me if this particular time I want to autostart. Super nice.

Read Full Post »

KDE notifications + MPD

To get mpd to show the currently playing song, one can easily use kdialog:

kdialog --title "Currently playing song" --passivepopup "`mpc | head -n1`" 3

which triggers a KDE notification popup for 3 seconds. Not very pretty, but it’s simple and can be triggered via xbindkeys or something similar.

Read Full Post »

As with Amarok it’s not possible to delete the currently playing song in the MPD with any client I know. So again here’s my script. This time with a lot more error control 😉

#!/bin/bash
# Change this to your mpd music directory.
music_directory='/var/lib/mpd/music'
if ! mpc &> /dev/null
then
        echo "mpc wasn't found. Please install first."
        exit 1
fi
if [[ `mpc | wc -l` != 3 ]]
then
        echo 'There is no song playing right now...'
        exit 2
fi
if [[ -z $MUSICTRASH ]]
then
        echo 'Please set $MUSICTRASH.'
        echo '  For example add this line to your .bashrc:'
        echo '  export MUSICTRASH=~/music/.trash'
        exit 3
fi
if ! [[ -d $MUSICTRASH ]]
then
        echo "$MUSICTRASH does not exist."
        exit 4
fi
file=`mpc --format '%file%' | head -n1`
path="$music_directory/$file"
if [[ -f $path ]]
then
        name=`basename "$path"`
        mpc del 0
        mv "$path" "$MUSICTRASH/"
        echo "'$name' moved to '$MUSICTRASH'"
fi

Also set the config variable where you want to move your trashed music files:

File: .bashrc

export MUSICTRASH=~/music/.trash

Har!

TIP: Use xbindkeys if you need fast, easy and desktop-environment-independent global shortcuts.

Read Full Post »

A little bash script takes care of deleting the current song, you just have to setup a shortcut somewhere.

#!/bin/bash
path=`dcop amarok player path`
if [[ $path != "" ]] # if player is currently stopped
then
        name=`basename "$path"`
        mv "$path" "$MUSICTRASH/$name"
        echo "Song moved to $MUSICTRASH" # output for usage in terminal
        dcop amarok player next # play next song to notify that something has happend
fi

And set the config variable where you want to move your trashed music files:

File: .bashrc

export MUSICTRASH="/mnt/data/music/.trash"

bash is so powerful, it’s always a pleasure 😉

Read Full Post »