Skip to content

Instantly share code, notes, and snippets.

@ibnsamy96
Last active November 19, 2023 00:43
Show Gist options
  • Save ibnsamy96/8971cbfce423ab0ed1b2d80119f68f6e to your computer and use it in GitHub Desktop.
Save ibnsamy96/8971cbfce423ab0ed1b2d80119f68f6e to your computer and use it in GitHub Desktop.
linux shell script that open apps when the system starts

Script to start apps in shell:

#!/bin/bash

# Open Google Chrome with specific tabs
google-chrome "https://www.google.com" "https://www.stackoverflow.com" "https://www.github.com" &

# Open Visual Studio Code
code &

# Open a new terminal window and navigate to the ./Work directory
gnome-terminal -e "bash -c 'cd ./Work; exec bash'"
# or if you use zsh: gnome-terminal -- zsh -c "cd ./Work; exec zsh"

To add the script to startup using the 'systemd' method:

  1. Create a new service file in the /etc/systemd/system directory. You can name it anything you want, but it must end with .service. For example, you could name it my_script.service. sudo nano /etc/systemd/system/my_script.service

  2. In the service file, add the following content and replace /path/to/your/script.sh with the actual path to your script:

    [Unit]
    Description=My Script
    
    [Service]
    ExecStart=/path/to/your/script.sh
    
    [Install]
    WantedBy=default.target
    
  3. Save and close the file and enable the service to start at boot: sudo systemctl enable my_script.service

  4. If you want to run it: sudo systemctl start my_script.service


To stop the script from running at startup, you can disable the systemd service. Here are the steps:

  1. Disable the service: sudo systemctl disable my_script.service

  2. Stop the service: sudo systemctl stop my_script.service

After running these commands, your script will no longer run at startup. If you want to run the script again at startup, you can enable the service again with the sudo systemctl enable my_script.service command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment