I like to have a top menu on my KDE screen with commonly used programs and links to scripts.
Commonly used programs include browsers, Libre Office, The Gimp and Konsole.
Items can easily be added by dragging an icon from the launcher menu or an icon for a script from within the Dolphin file manager.
I wished to add a new icon link to the top menu bar in KDE which would restart PulseAudio. At startup the microphone was not ready for use. Restarting PulseAudio was found to resolved this. This would be a temporary fix pending further investigation.
The Task
Create a script which could be run by a single icon click from a secondary KDE Plasma menu situated at the top of screen. This is useful for frequently used programs.
The script to be created was to restart the PulseAudio service. The audio didn’t always find the microphone of the webcam at startup. And sometimes the line out audio speakers.
The icon would run a pre-defined script to reset the audio once KDE was up and running, if the audio was an issue. This would be easier than opening Konsole and typing the required commands manually.
Script Location
You may wish to put the script in a directory under your home directory. However it’s possible for such scripts to become lost amongst other documents and images.
As an alternative you may wish to add the script to the directory
/usr/local/bin
This directory is frequently used for user added scripts.
Script Content
Create a new file, you may wish to give it the .sh extension to indicate that it is a script.
For this exercise I created a file called audiorestart.sh and located it within the /usr/local/bin directory.
Within the file I added the following as the first line.
#! /bin/bash
As scripts can be run in python, Perl, php, bash amongst others this first line is used to denote what will be used to run the script., in this case BASH.
Following this was the command(s) to be run, for example to restart the PulseAudio, giving as a whole:
#! /bin/bash systemctl --user restart pulseaudio.service systemctl --user restart pulseaudio.socket
Making the Script Executable
The script needs to be executable. Execute this comment
chmod +x /usr/local/bin/audiorestart.sh
Add Script Icon to Menu Bar
Using the Dolphin file manager navigate to the folder where the script has been added: /usr/local/bin. Drag the icon of the script up onto the menu bar. this will create a new menu bar entry.
The icon assigned to do this can be changed to something more appropriate. Right click on the item and from the pop-up menu select Properties. On the popup window click on the icon to show a further window where the replacement icon an be selected.
The popup properties window offers tabs for general, permission URL and Details. Under the General tab an icon is shown alongside the filename. Click on the icon and select your preference.





