I have a shell script. I want to configure my script to run automatically during startup. I know how to do this from GUI. But I wanted to do this from terminal. How can I do this?
On a primary research I found that the file needs to be moved to /etc/int.d/
directory. But this operation needs sudo permission. I wanted to do this without super user permissions.
I also found that there are files under ~/.config/autostart/
which are having some settings regarding the startup applications. But I don't know how to edit them to achieve this.
Can someone tell me the exact procedure to achieve this?
How to set up a startup launcher from command line
Like you mention in your question, commands can be run on log in by placing a launcher in
~/.config/autostart
Since the launcher is only used to startup a script, you only need the "basic" desktop entry keywords in the created.desktop
files: the keywords / lines you'd need at least:The (optional) line
X-GNOME-Autostart-enabled=true
will be added automatically if you enable/disable the autostart function of the launcher (it is set toX-GNOME-Autostart-enabled=true
by default)More on required fields, you can find here.
Example script
To create such a launcher from the command line, you would need a small script that would take the name of the starter and the command to run as an argument. An example of such a script below.
If I run it with the command:
It creates a startup launcher, running
gedit
when I login.The launcher is also visible in Dash > Startup Applications:
The script
Paste it into an empty file, save it as
set_startupscript.py
, run it by the command:What it does
~/.config/autostart
, taking the name and command as arguments.If a launcher with the name already exists in
~/.config/autostart
, it prints a message:I found an answer
cd to
~/.config/autostart/
. If you don'y have a folder named autostart then create one with that name using mkdir autostart.Now add the following file with the name
yourScript.sh.desktop
Done!