In today's HowTo, we're going to write a script to start Amarok playback on a schedule. You can play a streaming URL, as I do for a Friday afternoon Science Friday program which I like on NPR, or you can play a local file, or you can just have Amarok start to play whatever is at the top of its playlist.
This is a two-part task; first we need to write the script that will call Amarok, and second we need to create the Cron entry to have something start at a specific time. This probably could be written as one line in Cron but this is how I have it working.
First, create your script. I have it stopping Amarok with the -s flag, and then starting the URL that I want Amarok to play. (See other Amarok options at the command line with amarok --help ). I append the URL so that my playlist isn't wiped out. Create this file and save it somewhere, such as in your ~/scripts/ folder (note that the second amarok call has a URL listed, in case it gets a line break — this is only 5 lines long, see the screenshot)
#!/bin/bash
# Script to start Amarok, info at gnuski.blogspot.com
# http://gnuski.blogspot.com/2011/11/howto-use-amarok-as-alarm.html
DISPLAY=:0 /usr/bin/amarok -s
DISPLAY=:0 /usr/bin/amarok http://minnesota.publicradio.org/tools/play/streams/news.pls
exit
Here it is as a screenshot for formatting purposes, slightly different as it doesn't have the above comments:
Save that file (we'll call it ~/scripts/amarok_alarm.sh for this example) and make it executable, and let's tighten it by removing other people permissions as well (we don't need them changing our file to execute something evil!). You can run these commands, or right-click on the file and adjust its permissions:
linux-prompt$ chmod u+rwx ~/scripts/amarok_alarm.shYou should be able to test this at the command line if you wish; running this should start Amarok's playback:
linux-prompt$ chmod go-rwx ~/scripts/amarok_alarm.sh
linux-prompt$ ~/scripts/amarok_alarm.shOK, we got that working. Now we set up the Cron entry; again you can use crontab -e to edit your Cron Table, or you can use the KDE Task Scheduler (package named kde-config-cron) or something like that.
With KDE's Task Scheduler it looks like this:
In the crontab itself, it looks like this (crontab -l to see the cron table):
# m h dom mon dow command
#Start playing Science Friday
0 13 * * 5 /home/lefty/scripts/amarok_alarm.sh
Notice in the Cron Table, you have the Minutes column listed first (0), then the Hours column (13, aka 1pm). then the Date of Month (and number works for me), then the Month (all months), then the Day of Week (Fridays is when this program airs, and Friday is set with a 5). If you're not familiar with Crontab, I suggest you check out this article.
I hope that you found this article useful and please let me know if I can improve it or let us all know how you've put it to use! It's important to note that the computer must be powered on and not asleep, it must have internet access if you want to stream, it must have speakers...


0 comments:
Post a Comment