Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 2295  / 2 Years ago, mon, august 29, 2022, 7:20:36

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


More From » sound

 Answers
2

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.


[#35021] Wednesday, August 31, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kilusy

Total Points: 171
Total Questions: 110
Total Answers: 128

Location: Cayman Islands
Member since Sat, Dec 5, 2020
3 Years ago
;