LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   SUSE / openSUSE (https://www.linuxquestions.org/questions/suse-opensuse-60/)
-   -   KDE 4 Autostart Program Bash Script to Write Autostart Bash Scripts for You! (https://www.linuxquestions.org/questions/suse-opensuse-60/kde-4-autostart-program-bash-script-to-write-autostart-bash-scripts-for-you-802714/)

jdmcdaniel3 04-18-2010 01:11 PM

KDE 4 Autostart Program Bash Script to Write Autostart Bash Scripts for You!
 
I wrote a simple Bash script that will create autostart program scripts for you in /home/user/.kde4/Autostart. Copy and past the following code into Kwrite or other editor and then save the file as autorun in the folder /home/user/bin. Use the command "chmod u+x autorun" to make the program executable.

Code:

#!/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 LinuxQuestions.org Forums 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 "--------------------------------------------------------------------------------------------------------------"
    echo       
    read -p "Press <enter> to exit autorun..."
    echo ;;
"-l") echo "----------------------------------------------------"
    echo "List of Autostart files:"
    echo
    dir /home/$USER/.kde4/Autostart       
    echo "------------------------------------------------------"
    echo       
    read -p "Press <enter> to exit autorun..." ;;
"-d") cd ~
      if [ "$2" != "" ] ; then
        if [ ! -f .kde4/Autostart/$2.sh ] ; then
          echo "---------------------------------------------"
          echo "Autostart file: "$2".sh Does Not Exist!"
          echo "---------------------------------------------"
          echo
          read -p "Press <enter> to exit autorun..."
        else
          rm .kde4/Autostart/$2.sh
          echo "---------------------------------------------"
          echo "Deleted the Autostart File: "$2".sh"
          echo "---------------------------------------------"
          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 "------------------------------------------------------------------------"
          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

To use the program, open up a terminal session and type "autorun program" to create an autostart script file for you. Autorun allows to to create, list and delete autostart bash script files. When using a program name, it must be the actual name you must type in in the run command box, to make it work. If a program you wish to run requires options, add them to the end of your program name. Ex: autorun kwrite textfile.

Thank You,

smoker 05-03-2010 06:17 AM

I'm sure it's useful for KDE users, thanks.


All times are GMT -5. The time now is 01:13 AM.