I’d love to get my Ubuntu 20.04 Framework to play me a sound when I log in. Sound is working ok fine when I am using the machine. And I believe I have the correct setting enabled:
The best way is as follows if you want the traditional startup sound. I tested this myself, worked on 22.04, should be similar with 20.04. This will work on GNOME and KDE, except for the Start Up tool will differ (see above).
Start by creating a text file called sound. Paste in the following.
Hah! Tried adding the paplay … line to my .bashrc, but then of course it plays every time I open a terminal session. But adding the shell script to the startup activities screen worked like a champ. Thanks man!
Hah hah. Spoke too soon. This works great if I log out and then log back in while the machine is running. But it makes no sound on initial startup. Seems like there’s something weird in the way the mixer is initializing on boot.
#!/bin/bash
###################################
#
# Play a random file from a directory of sound files
#
# Charles Shapiro 17 Dec 2022
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see
# <https://www.gnu.org/licenses/>.
#
####################################
#
# Given a directory, get a random filename from it.
#
get_random_filename()
{
NUMFILES=$(ls $1 | wc -l)
FILENAME=$(ls $1 | nl -nln | awk /^$(($2 % ${NUMFILES} ))/'{ print $2 }')
}
#
# Main Line
#
PLAYEXEC=$( which paplay)
OPTSTR="D:R:"
RAND=${RANDOM}
DIR=/home/devel/Boot_Sounds
while getopts ${OPTSTR} ARG
do
case ${ARG} in
D) DIR=${OPTARG} ;;
R) RAND=${OPTARG} ;;
*) echo Oops. Usage: ${OPTSTR}
esac
done
get_random_filename $DIR $RAND
# set -x
${PLAYEXEC} ${DIR}/${FILENAME}