bash fun: alarm clock

Over time I’ve become immune to most kinds of alarm clocks. The only thing loud enough to wake me is music coming from my 5.1 speakers. But I’m really particular about what I want to wake up listening to, and it can’t be the same song every day. So, I came up with this thing:

#!/bin/bash
function createAlarm
{
  command="gst-launch-0.10 playbin uri=\"file://"$1"\""
  echo ${2}" "${3}" * * * "${command}|crontab -
}
if [ -z "$1" ]; then
  echo Usage: $0 " "
  exit
fi

if [ -z "$2" ]; then
  min=00
else
  min=$2
fi
if [ -z "$3" ]; then
  hr=07
else
  hr=$3
fi

pattern=$(echo "$1" |sed -r -e 's/\s/*/g' -e 's/.*/*&*/')

IFS=$'\n'
declare -a results
results=($(find -H ~/Music/ -iname "$pattern" -printf "%p\n%f\n"))

if [ ${#results} -eq 0 ]; then
  echo "No results"
  exit;
elif [${#results} = 2]; then
  #dont show menu
  createAlarm ${results[0]} $min $hr
else
  for i in `seq 1 2 ${#results[*]}`
  do
    echo $((($i+1)/2))") "${results[i]}$'\n'
  done
  echo -n "select# "
  read i
  createAlarm ${results[$(($i*2-2))]} $min $hr
fi

It searches through my music based on the keywords I give, then it creates a crontab which uses gstreamer to play the song. Incredibly useful, and much faster than navigating a GUI to find a song, set a time, etc like I used to do before. Try it!

Advertisements

~ by hellfeuer on February 8, 2008.

One Response to “bash fun: alarm clock”

  1. Wouldn’t it make more sense to use at instead of crontab?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: