How to run raycast script that includes `sudo`
Summary
Write the script that includes
sudo
“separately”.Add the
/path/to/the/script
to some kind of sudo whitelist(sudoer
file)Make a raycast script that includes
sudo /path/to/the/script
Example
The script that includes sudo
I wanted to make a shortcut to run the following script (written by me!):
but the content isn’t important. Assume that we have an awesome script as follows:
/absolute/path/to/my_sudo_script.sh
#!/bin/bash
sudo rm -rf /
Don’t forget to make the script executable with the following command:
chmod +x /absolute/path/to/my_sudo_script.sh
Add the script to sudoer
First, open the sudoer
file with the following command:
sudo visudo # this will open the sudoer file with vim
sudo EDITOR=nano visudo # use this if you prefer nano (like me!)
Then, add the following line at the end of the file:
your_username ALL=(ALL) NOPASSWD: /absolute/path/to/my_sudo_script.sh
To check your username, you can use
whoami
command.
Write the raycast script that runs the script above
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title type the title you want
# @raycast.mode compact
# Optional parameters:
# @raycast.icon 🍻
# @raycast.author gwonhong
# @raycast.packageName Type The Package Name You Want
# @raycast.description type the description you want
sudo /absolute/path/to/my_sudo_script.sh
Now, you can run the script via raycast!
Subscribe to my newsletter
Read articles from Gwon Hong directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by