4

I have read questions on Changing startup sound in Ubuntu and Changing startup music in Ubuntu.

I understand how to rename 'desktop-login.ogg' and copy the sound I want as 'desktop-login.ogg'.

My question is -is there a way I can play different sounds (i.e. choose a random file from a set of files in a defined music folder) each time I login? It may sound silly, but if possible I would like to play different sounds.

I am guessing that this may be perhaps possible by running some kind of script which replaces/renames the desktop-login.ogg file each time I shutdown, so that a new file is ready to be played on the next startup. But I don't know how to copy a new file from a particular folder to desktop-login.ogg upon each shutdown, nor do I know where the script should reside.

I would appreciate it if someone could tell me how to do it, or if there is an easier way of doing this.

Thank you

2 Answers 2

3

Assuming you want a music file to play from a defined folder of files, this is one way to go (open a terminal to execute the commands):

  1. Choose the music player:

    I am suggesting vlc but other choices like mplayer also work. If you have only ogg files canberra-gtk-play or paplay is fine.

    Playback check:
    cvlc --play-and-exit path/to/Music/song.ext
    mplayer path/to/Music/song.ext
    paplay path/to/Music/song.ext
    canberra-gtk-play -f path/to/Music/song.ext

  2. Create a new script:

    sudo gedit /usr/bin/play_rand_login.sh

    and paste the following:

    #!/bin/bash
    files=(/home/me/Music/*)
    cvlc --play-and-exit "${files[RANDOM % ${#files[@]}]}"

    Change the music path /home/me/Music to your actual folder.
    Replace cvlc with your player choice and close the file.
    Now make the file executable:
    sudo chmod +x /usr/bin/play_rand_login.sh

  3. Open the Startup Applications Preferences, choose the Gnome login sound and edit the command to read:

    /usr/bin/play_rand_login.sh

  4. Logout and login to test if all is well.

Notes:

  • It is not guaranteed to have a different file playing at two subsequent logins but if you have many files the chances are high.
  • Tested to work at on Ubuntu 12.04 (using Gnome 3).
  • The bash random file choice is coming from a stackoverflow question.
1
  • thank you very much for providing detailed instructions. I appreciate it. I will try it out as soon as I get a chance.
    – user82171
    Oct 13, 2012 at 6:52
1

You can use canberra-gtk-play to play audio file at startup.

Command to run Canberra-gtk-play /usr/bin/canberra-gtk-play -f <file_name.ogg>

You Startup Applications to play this during Ubuntu start up.
Name: Startup Sound
command: /usr/bin/canberra-gtk-play -f file_name.ogg
Comment: Some comment

3
  • thank you for your response and informing me about the application Canberra-gtk-play. I will try it out. Sorry, I was not clear in my post above that I am looking for a way to automatically change the filename and play a different file after each startup.
    – user82171
    Oct 11, 2012 at 10:46
  • 1
    I think your question is clear enough. But to be more precise I think you could say "choose a random file from a set of files in a defined music folder".
    – rosch
    Oct 11, 2012 at 13:40
  • @rosch, thank you for your suggestion. I will modify my question.
    – user82171
    Oct 13, 2012 at 6:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .