You are not logged in.

#1 2008-04-16 01:31:05

nabl
Member
Registered: 2008-04-04
Posts: 3

HOWTO: Startup/Shutdown Sounds in Openbox

In this tutorial, I will show you how to add startup and shutdown sounds with Openbox, a light-weight window manager. In theory, this should work with any window manager that uses a startup script (or, if you use the startx command, .xinitrc could be used for the same effect); however, I will be focusing on Openbox, so you will have to adapt these instructions for use with other window managers.

We'll start with a quick background story: I was in a "tweaking" mood a few days ago, and I figured I'd try to set up some startup and shutdown noises for use with Openbox. After a few minutes of messing around, I got it working. I searched to see if there were any tutorials like this, and since there weren't, I figured I would share my knowledge--that's what tutorials are for, right?

NOTE: I originally posted this on ubuntuforums.org; therefore, there may be some differences (I tried to fix most of them). Even though I did this on Arch originally, I wrote it targeted toward Ubuntu users. I didn't get much of a response--there must not have been too many Ubuntu/Openbox users looking for that. big_smile Please point out any inconsistencies, and I'll fix them as soon as possible.

Now that we have that out of the way, let's get started.

-----------------------------------------------

Step 1: Installing the necessary application(s).
First off, we will be using a commandline program called play. It is part of the sox package, so let's install that first (you likely have most of its dependancies already).

# pacman -S sox

If you'd like, you can cd to a directory with music in it and type play name-of-sound-file.extension to test that it is working. If you don't have any files to try it on, you can do this later after downloading your desired sound files in step 3.

I also have sudo set up; you will need to set this up to run the shutdown commands from a script as I have them. There is a section in the ArchWiki that will help in setting it up if you want. As for the commands with sudo in them, you can just run them in a root terminal.

In addition to that, I will be working with obmenu, a program for editing Openbox's menu from a GUI; however, it will work just as well to edit the menu by hand. I assume you already have a preferred method of editing your menu, but if you want to try obmenu, it's only a pacman command away:

# pacman -S obmenu

Step 2: Setting up shutdown privileges.
For this section, I will be adapting a section from a great guide written by urukrama here. We're going to be running a shutdown command from a script, so we need to have it set up to work without any interaction--in this case, that means removing the need for a password for the shutdown command.

To do this, type in the following command into the terminal:

sudo visudo

This will open up the sudoers file, which is used to specifiy user permissions for actions that require root priveleges. For those of you unfamiliar with Vim (I'm with you tongue), just press i on your keyboard to enter interactive mode, which allows you to edit the file. Then, enter the following line at the end of the file:

%wheel     ALL=NOPASSWD:/sbin/shutdown

Then press escape to exit interactive mode. Lastly, type in :wq followed by pressing enter to save and exit. Now you can use the sudo shutdown command without entering a password.


Step 3: Getting the desired sound files.

Now we come to the fun part of the guide--finding the sounds that we want.

There are plenty of startup and shutdown noises floating around the web; I went to gnome- and kde-look to check out theirs (the same are available at both sites). Here's a link to the System Sounds section at gnome-look. You can look through and download the ones that interest you; once you have listened to a few and found one that you like, go on. Just for reference, I chose the Dream pack. It fits very nicely with my current setup and theme.


Step 4: Setting up the shutdown/startup scripts.
If you haven't already (in the last step), extract the sound files from the package that they downloaded in. Then, look through the files and find the startup and shutdown noises. For me, they were titled Dream Intro.ogg and shutdown.ogg, respectively. Move these files into their own folder. I chose ~/.startup--on my Arch install, it was empty. You may want to put it into a different folder/sub-folder, preferably somewhere in your home folder. You can now remove all the other sound files--hypothetically speaking, it probably wouldn't be too hard to get other sounds (such as minimize, maximize, etc., if provided in the sounds package you chose) working with Openbox, but that is beyond the scope of this tutorial. Now, go to the folder in which you placed the startup and shutdown noises. For simplicity's sake, we're going to place the scripts in this same folder.

We're going to be making two scripts here--one for reboot and one for shutdown. Open up your text editor of choice here and enter the following line (replacing the "/path/to/file.extension" with the path to your shutdown sound):

play /path/to/file.extension && sudo shutdown -r now

For me, it looked like this:

play ~/.startup/shutdown.ogg && sudo shutdown -r now

What this does is play the sound file specified and, once that is done, moves on to the reboot process (that's what && does). Save this as reboot.sh. Now make a new file, this time for the actual shutdown. It will be the same as the first except the shutdown command will now be sudo shutdown -h now. Here's what mine looks like:

play ~/.startup/shutdown.ogg && sudo shutdown -h now

Save that one as shutdown.sh. At this point, we have completed the scripts for both shutdown commands. Next, open up your Openbox autostart script (should be in /home/<user>/.config/openbox/autostart.sh, where <user> is your username) with the text editor of your choice. You probably already have a few different things in here; if not, it doesn't really matter. Just add the following line to your autostart file (as you can see, I used quotes around this one because this file had a space in its name--you'll want to do the same. You can also use a backslash before the space):

play "/home/<user>/.startup/Dream Intro.ogg"&

Make sure you keep the ampersand (&) in tact; otherwise, the script will wait until the sound is done playing before completing the rest of the processes. I recommend that you place the sound file at the beginning of the script so that it starts first--the way I have it set up, everything is ready to go by the time the login sound ends (sooner, actually). Now that we've come this far, we're almost done.


Step 5: Adding the shutdown options to the Openbox menu.
At this point, the login sound will be working; however, we still need to set up the shutdown sounds. To do this, we will add a section to the Openbox menu that runs the two scripts we made in the last step.

Either open up obmenu or use your preferred text editor and open up menu.xml (should be in ~/.config/openbox/menu.xml). As I said, we will be adding two items: one for rebooting and another for shutting down. In obmenu, you can add a new submenu wherever you want (I chose the bottom of the menu) and name it Power (or whatever else you'd like). The first we'll add is named Restart. For the execute line, add the following:

bash /path/to/reboot.sh

For me, this path is ~/.startup/reboot.sh. As for the second, name it Shut Down and for the execute command put the following:

bash /path/to/shutdown.sh

Again, for me this is ~/.startup/shutdown.sh. Here is what the section in my obmenu looks like:

obmenugj6.png

As for the pure XML, here it is (I replaced my name with <user> wink):

<item label="Restart">
<action name="Execute">
  <execute>bash /home/<user>/.startup/reboot.sh</execute>
 </action>
</item>
<item label="Shut Down">
 <action name="Execute">
  <execute>bash /home/<user>/.startup/shutdown.sh</execute>
 </action>
</item>

With obmenu, just save it, and your menu will be refreshed. When hand-editing the menu.xml file, you have to remember to Reconfigure Openbox (it will be in your menu unless you've removed it).

-----------------------------------------------------------------------------

And with that, you should have working startup and shutdown sounds. You can test it by right clicking on your desktop and selecting one of your new shutdown options. You should have a sound play followed by the normal shutdown routine. Then when your computer starts back up, you will have a pleasant noise after logging on.

I hope that helped you! Please point out any errors that you see, and I'll correct them as soon as possible.

Offline

#2 2008-04-16 01:59:24

PuppyWhirl
Member
Registered: 2008-04-07
Posts: 99

Re: HOWTO: Startup/Shutdown Sounds in Openbox

Nice tutorial. I was wondering, I noticed you have a games tab. Do you know how to properly execute games. I am trying to get steam games working also Call of duty 4 as tabs under obmenu. Could you help me out?

Thanks!

Offline

#3 2008-04-16 02:15:26

bender02
Member
From: UK
Registered: 2007-02-04
Posts: 1,328

Re: HOWTO: Startup/Shutdown Sounds in Openbox

Why don't you post it on the wiki?

Offline

Board footer

Powered by FluxBB