Lately, I've been endeavouring to automate some of the basic and mundane tasks I regularly perform on my computer. One task that I aim to automate is the ability to open any of my popular social media platforms (Instagram, Facebook, WhatsApp) with a simple command in the terminal.
After finding the solution to the problem, I encountered another issue: I had to navigate to the script's directory every time I wanted to use it. This process was not only cumbersome but also undermined the automation I sought. Determined to resolve this, I conducted some research online, and here are the steps I followed to make my script globally accessible in the terminal:
First, find the path to the interpreter you are using by typing the following into a terminal:
$ which python3
Next, add the following line at the top of the script file:
#! /usr/bin/python3
(Note: This should be the path to the interpreter displayed by the command in the first step.)
Change your script's permissions with:
chmod u+x socials.py
Now, move your script to the following directory. You need administrator privileges to do this. Type the following command (replace `<directory>` with the desired location):
sudo mv socials.py /usr/local/bin/<directory>/socialscamelCasesnake_case
(Note: You have to remove the file extension if the file has one, and change it to a suitable name using camelCase or snake_case.)
Alternatively, you can create a link to the script without moving the file using the following command:
sudo ln -s /path/to/socials.py /usr/local/bin/socials
References:
1. Linux custom executables are available globally.
2. How to make a globally available executable script in the scripting language of your choice.