KDE Application Autostart Script: Automatically Made For You!

If you are new to openSUSE and KDE, you may wonder where the Startup folder is located so you can automatically run some application when KDE first starts up.

KDE is different in that you must create a script file to tell KDE what application you want to run at startup.

I have written a script file that can be used to automatically create an autostart script located in the user folder ./kde4/Autostart.

You can use KWrite to create the script and save it in the folder /home/username/bin. Just copy and past the script file as written below into KWrite then save it.

In Terminal, change to the bin folder and use the command “chmod u+x autorun” to make it executable.

Once created, use the syntax:

autorun application

Your application will then be automatically run each time KDE is started. The application will run only for a specific user, where the script is located, logs into KDE.

#!/bin/bash

A sript file to create an Autostart script for a KDE Application

KDE autostart script file name “autorun”

Create script file /home/username/bin/autorun

use the command “chmod u+x autorun” to make it executable

Written for openSUSE Forums 4-17-2010

if “$1” != “” ]
then
cd ~
echo “#!/bin/bash” > .kde4/Autostart/$1.sh
echo $1 >> .kde4/Autostart/$1.sh
echo
chmod u+x .kde4/Autostart/$1.sh
echo “------------------------------------------------------------------”
echo "Created Script File "/home/$USER/.kde4/Autostart/$1.sh
echo “------------------------------------------------------------------”
echo
else
echo
echo “Must Enter Program name to be Automatically Run!”
echo
echo “Syntax is: autorun program”
echo
fi

End of Script File

Let me know if you have any questions or problems with this script.

Thank You,

Well, if you liked the simple program autorun, why not add some more functionality? In my next example, we add the ability to list the programs in .kde4/autostart (autorun -l) and delete a program in .kde4/autostart (autorun -d program).

#!/bin/bash
# A sript file to create an Autostart script for a KDE Application
# KDE autostart script file name "autorun"
# Create script file /home/user/bin/autorun
# use the command "chmod u+x autorun" to make it executable
# Written for openSUSE Forums 4-18-2010
#
case "$1" in
"") echo
    echo "Must Enter Program name to be Automatically Run!"
    echo "The File Extension .sh is assumed and should not be entered."
    echo
    echo "To Add a New Autostart Program."
    echo
    echo "Syntax is: autorun program "
    echo
    echo "To List All Programs in Autostart."
    echo
    echo "Syntax is: autorun -l"
    echo
    echo "To Delete an Existing Autostart Program"
    echo
    echo "Syntax is: autorun -d program"
    echo	;;
"-l") echo 
    echo "List of Autostart files:"
    echo
    dir /home/$USER/.kde4/Autostart	
    echo	;;
"-d") cd ~
      if  "$2" != "" ] ; then
	if  ! -f .kde4/Autostart/$2.sh ] ; then
	  echo 
	  echo "Autostart file: "$2".sh Does Not Exist!"
	  echo
	else
	  rm .kde4/Autostart/$2.sh
	  echo
	  echo "Deleted the Autostart File: "$2".sh"
	  echo
	fi
      else
 	  echo 
	  echo "-d Delete Command Must be followed by a Autostart filename to Delete!"
	  echo
      fi	;;
*)  cd ~
    echo "#!/bin/bash" > .kde4/Autostart/$1.sh
    echo $1 >> .kde4/Autostart/$1.sh
    echo 
    chmod u+x .kde4/Autostart/$1.sh
    echo "------------------------------------------------------------------"
    echo "Created Script File "/home/$USER/.kde4/Autostart/$1.sh
    echo "------------------------------------------------------------------"
    echo	;;
esac
# End Script File

As always, let me know what you think about this new script file.

Thank You,

While we (or I) are having fun with script files, lets add the ability to add program options, up to four, for the program we want to autorun. Remember, the program name must be what you would enter in the menu Run Command box, to make it work. Lets suppose we wanted to run KWrite at KDE startup and have it open our autorun script. The terminal session command using autorun to do this would be:

autorun kwrite /home/$USER/bin/autorun

#!/bin/bash
# A sript file to create an Autostart script for a KDE Application
# KDE autostart script file name "autorun"
# Create script file /home/user/bin/autorun
# use the command "chmod u+x autorun" to make it executable
# Written for openSUSE forums on 4-18-2010
# This program is ran in the Terminal mode with normal user rights
#
case "$1" in
"") echo 
    echo "--------------------------------------------------------------------------------------------------------------"
    echo "Must Enter Program name to be Automatically Run! The File Extension .sh is assumed and should not be entered."
    echo
    echo "1) To Add a New Autostart Program.          		Syntax is: autorun program "
    echo
    echo "2) To List All Programs in Autostart.       		Syntax is: autorun -l"
    echo
    echo "3) To Delete an Existing Autostart Program. 		Syntax is: autorun -d program"
    echo "--------------------------------------------------------------------------------------------------------------"	
    read -p "Press <enter> to exit autorun..."
    echo ;;
"-l") echo "----------------------------------------------------" 
    echo "List of Autostart files:"
    echo
    dir /home/$USER/.kde4/Autostart	
    echo "------------------------------------------------------"
    echo	;;
"-d") cd ~
      if  "$2" != "" ] ; then
	if  ! -f .kde4/Autostart/$2.sh ] ; then
	  echo "---------------------------------------------"
	  echo "Autostart file: "$2".sh Does Not Exist!"
	  echo "---------------------------------------------"
	  read -p "Press <enter> to exit autorun..."
	else
	  rm .kde4/Autostart/$2.sh
	  echo "---------------------------------------------"
	  echo "Deleted the Autostart File: "$2".sh"
	  echo "---------------------------------------------"
	  read -p "Press <enter> to exit autorun..."
	fi
      else
 	  echo "------------------------------------------------------------------------"
	  echo "The Delete Option Must be followed by an Autostart filename to Delete!"
	  echo "                 Syntax is: autorun -d program"
	  echo "------------------------------------------------------------------------"
	  read -p "Press <enter> to exit autorun..."
      fi	;;
*)  cd ~
    echo "#!/bin/bash" > .kde4/Autostart/$1.sh
    echo $1 $2 $3 $4 >> .kde4/Autostart/$1.sh
    echo 
    chmod u+x .kde4/Autostart/$1.sh
    echo "------------------------------------------------------------------"
    echo "Created Script File "/home/$USER/.kde4/Autostart/$1.sh
    echo "------------------------------------------------------------------"
    echo
    read -p "Press <enter> to exit autorun..."	;;
esac
# End Script File

Why not create autorun as shown above using kwrite, save your file in /home/user/bin, use the chmod u+x autorun command to make it executable and then try the terminal session autorun command “autorun kwrite /home/$USER/bin/autorun” then log out of KDE. Your Autostart scripts will run each time you log back into KDE. Remember all forum comments are welcome, even to say enough already, we get it. lol!

Thank You,

That’s a lot of work for:

Start KDE4, start Systemsettings, Advanced Tab, Autostart. It has a nice interface to do things like this :wink:

Thanks for sharing the script, but to be fair, the first part is by no means true. Dropping a shortcut in ~/.kde4/Autostart is enough, the above does the same.

Yes, as always, there is more than one way to skin a cat, as they say. But, not if you want to learn how to write a script file and possibly do something useful you can use while in the terminal mode. And, thanks for your comments…

Thank You,

jdmcdaniel3](https://forums.opensuse.org/member.php/43440-jdmcdaniel3)
https://forums.opensuse.org/images/novell/user-offline.png
Thanks for the useful script.

I’m wondering,
Unless the script implements something that is very specific to KDE
It might be better to “ExecStart” in a Unit file if you want to start something that’s not specific to a particular Desktop.

TSU

But that’s something completely different!

A systemd unit (or sysvinit service for that matter) is started during boot, not at login.
It is started as root, not as user (although it could run a program as any user of course).
And obviously you cannot run GUI applications by a systemd unit, because there is no X session where they could run.

If you do want to be independent of KDE, you could create a .desktop file in ~/.config/autostart/ though, with an “Exec=” line that starts your program. This should be respected by all desktop environments.

Thanks for the script. Always enjoy when people share their stuff. I usually end up learning something new, either from the script, or the comments :slight_smile:

On 2014-06-02 00:26, andy77586 wrote:
>
> ‘jdmcdaniel3
> (https://forums.opensuse.org/member.php/43440-jdmcdaniel3)
> [image:
> https://forums.opensuse.org/images/novell/user-offline.png]
> Thanks for the useful script.

Please have a look at this thread


Cheers / Saludos,

Carlos E. R.
(from 13.1 x86_64 “Bottle” at Telcontar)