Jan 18 2008

How-to: Use Your Ubuntu Computer as a Music Alarm Clock

Tag: how-to, music, software, ubuntuScott Wegner @ 7:19 pm

There are many music players that offer the functionality to wakeup to a song or playlist– both on Linux or Windows. But with each option I’ve tried, I’ve never been really happy with the results. For such a simple task, it always seemed overly-complicated. Also, the main downside I found in using a media player plugin, is that you’ll need to have the player running for it to actually work in the morning. Below I describe how to create your own music alarm clock, using only command-line utilities found on most Linux distributions. It uses quite a few different tools, and the tutorial will hit on quite a few different concepts. So, without further adieu…

  1. The first thing you will need is to create a playlist. I used Rhythmbox, since that’s where I store all of my music anyway. Create a playlist with songs you’d like to wake up to. When you’ve got enough, save it in .m3u format, somewhere where you’ll find it later. I put mine in my home directory.
  2. Next, we’ll need to make sure we have all the tools for the job. We’ll be using cron to schedule our tasks, amixer to set our volume, and mplayer to finally play our music. To make sure you have each of these installed, issue the following command:

    sudo aptitude install cron alsa-utils mplayer

  3. Next, we need to actually add the scheduled task. First I’m simply going to give you the commands, and I’ll explain what’s going on afterwards. In a terminal, enter the command:

    crontab -e

    Note: this will open your default text editor, which if you haven’t set it, will probably default to vim.

  4. Go to the end of the page by pressing Shift+G. Then start a new line pressing “o”. Once you’re there, type in or paste the following line:

    30 7 * * 1-5 /usr/bin/amixer set PCM 35\% && /usr/bin/X11/xterm -display :0 -bg black -fg white -e /usr/bin/mplayer -shuffle -playlist ~/.alarm-playlist

  5. Press “ESC” to stop typing. Then enter the command “:wq” (no quotes) to save and quit. If everything went well, you should see the line:

    crontab: installing new crontab

Cool, you’re done! Now, let me explain what all that was, so you can go back and customize it on your own. Remember, any time you want to learn more about a command, you can use the “man” command. For example,

man crontab

to learn about crontab.

So first of all, we used “aptitude” to install a few packages from the Ubuntu repositories. This is probably familiar to you, or you may be using “apt-get”. They are basically the same, but “aptitude” has a few advantages– you should switch to using it if you haven’t already.

Then, we used “crontab -e”. Cron is the name of the task scheduler in Linux, and this command opens up our own personal “scheduled task list”. You can always use “crontab -e” to edit your tasks, or “crontab -l” just to view them.

Now, on to that crazy line I had you type in:

30 7 * * 1-5 /usr/bin/amixer set PCM 35\% && /usr/bin/X11/xterm -display :0 -bg black -fg white -e /usr/bin/mplayer -shuffle -playlist ~/.alarm-playlist

Each entry in your personal crontab has the following format:

minute hour day-of-month month day-of-week command

So, in our case, our “minute” is 30, “hour” is 7, day-of-month is * (any), “month” is * (any), “day-of-week” is 1-5, and “command” is… the rest of that. This basically means that we’ve scheduled our command to execute at 7:30 am on Monday through Friday. Changing these options should be self explanatory. Now, let’s pick apart our “command” one part at a time.

/usr/bin/amixer set PCM 35\%

First thing to note, is that it’s a good idea to use full paths for any command you execute from cron. To find out the full path to a command, use

which {command}

In this case, we’re using amixer, which is a utility for changing the volume on your computer. I set mine to 35% to wake up to, but you can use anything. Also note here that we can’t use simply “35%”, because cron uses ‘%’ as a special character. Therefore, we preceed it with ‘\’.

Next thing to notice is “&&”. This essentially strings two commands together– it won’t start the next command until our first one has finished. So, onto our next command:

/usr/bin/X11/xterm -display :0 -bg black -fg white -e …

This is actually another compound command. xterm is another terminal that we are going to launch our music alarm in, so we can easily shut if off in the morning. We set all sorts of parameters to make the terminal look nice, but the important one is following the “-e”: that’s the command we will run in the new terminal:

/usr/bin/mplayer -shuffle -playlist ~/.alarm-playlist

Ahhh, finally, this is where we finally play our music. mplayer is a command-line music player with a very basic interface, and easy controls. You can run this line in a normal terminal now to make sure it works. We use the parameters “shuffle” to randomize our playlist, and then “-playlist …” to tell it what to play. Make sure you change “~/.alarm-playlist” to your own location.

And we’re done! At this point you should have a fully-functioning music alarm clock. Now go back and tweak it out with preferences that work for you.

Bonus: Move the alarm clock command to a shell script, and keep increasing your volume every minute or so.

If you're new here, you can subscribe to automaticable's RSS feed by clicking here. Or, you can get post updates through your email. Thanks for visiting!


Jan 18 2008

How-to: Mount a Network drive in Ubuntu

Tag: linux, ubuntuScott Wegner @ 3:16 am


Recently, one of my roommates bought an external network drive, so everyone in the house can upload their music and movies. It’s hooked right into the network through the router so it’s easy for anyone to access– pretty cool stuff. It was pretty simple to setup in Windows, but it took a little bit of research for Ubuntu. Specifically, we have Maxtor “Shared Storage II” hard-drive, and I wanted it to auto-mount each time I reboot my computer. I figured it out using the tutorial here, but the basics are below.

  1. First you will need to install the “smbfs” package. This is what we will use to mount the drive.

    sudo aptitude install smbfs

  2. We will also need a folder to mount the drive in. I used /media/public.

    sudo mkdir /media/public

  3. Then, we need to edit /etc/fstab. This is where we add all the information needed to find and mount the drive. Open /etc/fstab using the command:

    gksudo gedit /etc/fstab

    At the end of the file add the following lines:

    # Mount our network drive
    //SERVER/SHARE /MOUNT-POINT smbfs guest 0 0

    Where “SERVER” is the name of your drive on the network. This can be either a name or IP address. For example, mine was “MAXTOR”. Replace “SHARE” with the folder in the drive you’d like to mount– mine was “Public”. “MOUNT-POINT” is the directory we created earlier, such as “/media/public”. The rest of the parameters have to do with permissions, and also where you can add advanced options. For more information on the advanced preferences, see

    man mount.smbfs

  4. The final step is to tell the system to reload /etc/fstab and mount our drive. Do this with the command:

    sudo mount -a

    Then, you’re done! At this point you should be able to see the files in your drive with the command

    ls /MOUNT-POINT


Jan 15 2008

Ubuntu Desktop Course

Tag: ubuntuScott Wegner @ 6:31 am


From the makers of Ubuntu, there now exists an official Ubuntu 7.10 Desktop Course. This really shows the strength of the open source community; the Ubuntu team really goes full-circle with their support. The course is completely free (in both senses of the word), and available for download here. There is a student version, as well as a professor version.

Although it’s obviously intended to be taught in a mentoring or classroom environment, this would be a good read for anyone interested in moving to Linux. The read would probably be pretty rudimentary for somebody with a background Linux. However, it would be an excellent overview for somebody not only interested in using Ubuntu, but actually understanding what’s going on.


Jan 07 2008

Ubuntu Tutorial of the Week

Tag: linux, ubuntuScott Wegner @ 7:00 am

In my opinion, the best part of the open source community, is that it really is a community. There is all sorts of knowledge to be gained through the many freely-available resources for Ubuntu, and all open-source alike.

This evening, I found another little gem, called the “Tutorial of the Week,” hosted on the Ubuntu forums. Each week a new tutorial is posted. Some more useful than others, but they are all high-quality. You can subscribe to the weekly tutorials by subscribing to the RSS feed for this forum topic. This week’s tutorial is about Magic SysReq keys, which are helpful when your Linux computer freezes up.


Jan 03 2008

Last.fm on Ubuntu

Tag: lastfm, music, ubuntuScott Wegner @ 7:34 pm

I have been using Last.fm for a few years now, and it’s been one of those services that keeps getting better the longer you stick with it. In case you’re not familiar, it’s an online social network that creates a profile based on the music you listen to you. From there, it can recommend new music, as well as show how musically “compatible” you are with your friends.

One of the most useful features is the free streaming radio. Last.fm creates dynamic stations with music from your musical profile, music similar to a particular artist, or from a tag. There are many options for listening to these streaming stations on Ubuntu, and I’d like to compare each of them.

Last.fm Official Client
Last.fm has released their own client for listening tostreaming content from the desktop. It’s a pretty full-featured interface, as far as you can go with a streaming radio client. Also, it has access to much of the content that you would find on the website.
Pros

  • Full-featured desktop client
  • Artist bios and profiles
  • Access to your Last.fm profile

Cons

  • A little bulky
  • Closed source

Installation

sudo aptitude install lastfm

Last-Exit
Last-Exit is a lightweight alternative to t
he official client. It offers all of the basic functionality, and cuts down on all the frill. It’s a good substitute if you are having trouble with the official client.
Pros

  • Lightweight
  • Open-source
  • Integrates well with the GNOME desktop

Cons

  • No album art or advanced functionality

Installation

sudo aptitude install last-exit

Rhythmbox Last.fm Plugin
If you are already using Rhythmbox for the rest of your music needs, then the Rhythmbox plugin is a great option. It offers all of the Last.fm stations, through the Rhythmbox interface. It doesn’t have the artist biographies that the official client does, although it does integrate album art.
Pros

  • Rhythmbox integration
  • Already installed with Rhythmbox

Cons

  • Bulky if only used for Last.fm

Installation

Already installed, enable it in the Rhythmbox Plugins dialog.

Last.fm Website
If you prefer not to install a desktop client, you can always stream radio through your web browser. All it requires is a flash plugin and a Last.fm username.
Pros

  • No need to install a client
  • Well-integrated with the rest of the Last.fm website

Cons

  • Requires leaving your browser open

Installation

None





Jan 02 2008

A New Year, A New OS

Tag: linux, ubuntuScott Wegner @ 10:43 pm


I’ve been home with the family for a couple weeks for the holiday season now. I took a break from sitting by the fire and enjoying stories of Christmas-past, to set my brothers with Ubuntu. One of them just bought a new desktop, and was willing to give it a shot on his aging laptop, and the other wanted to setup a dual-boot, to test the Linux waters before making the switch.

Needless to say, I’m now on constant call for tech-support. Neither of them have any Linux experience, but they’re pretty tech-oriented anyway. It’ll be a good learning experience for all of us. In fact, I’ve already picked up a few pointers to share:

  • Don’t assume that cool desktop effects are going to work on your old hardware. The new compiz is cool, but old cards just can’t hack it. For some Nvidia cards, it’ll require using the proprietary video driver, which is a whole new can of worms.
  • Use local repository mirrors. Just like a fresh Windows install, expect about 100 updates after you’ve got things installed. You can cut the download time in half by finding a mirror in your area.
  • Discourage sudo. Coming from Windows, there is an expectation that you should have access to everything. In Linux, there’s restrictions there for a reason. Instil a fear of root access, as a means to save the new user from himself. And when you must go editing system files, make backups.
  • Show off the terminal. This may sounds contradicting to the last point, but Linux is built around the command-line. While your setting things up through the GUI, make sure to mention the alternatives. If they’re going to use Linux, they’re going to have to dabble in the terminal eventually.
  • Teach them to search. Starting off, they’re obviously going to have questions, and more than you’ll probably have time to answer. Show them the wonders of Google. There’s even a search engine, Uboontu, that’s tailored exactly for Ubuntu and Linux questions.
  • Setup remote access. Just because the relatives are leaving and the holidays are ending, doesn’t mean that the computer trouble will. Make sure you have an adminstrator account setup, as well as ssh and vnc access. This means setting up the server, and opening ports on the router.
  • Talk it up. Finally, you need to convince them that they made the right move going to Linux. Ubuntu takes some getting used to, so make them feel they’ve made a worthy investment by bragging about it a little bit. Talk about how easy it is to install software, how everything is free and legal, and that they won’t get viruses. Make them like it.

« Previous Page