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 Answers2

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.
rosch
  • 8,168
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

devav2
  • 37,290