Last active
June 27, 2024 10:19
-
-
Save felipealfonsog/6da15b5d6afab68614c0f4f095fef103 to your computer and use it in GitHub Desktop.
This Bash script allows users to easily shutdown, suspend, or reboot their system via a simple menu interface.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Action Script for macOS | |
# Author: Felipe Alfonso González | |
# GitHub: github.com/felipealfonsog | |
# Contact: [email protected] | |
# License: BSD 3-Clause License | |
# Function to display the options menu | |
display_menu() { | |
echo "Select an option:" | |
echo "1. Shutdown" | |
echo "2. Suspend" | |
echo "3. Reboot" | |
echo "4. Abort" | |
} | |
# Function to perform the selected action | |
perform_action() { | |
choice=$1 | |
case $choice in | |
1) | |
sudo shutdown -h now | |
;; | |
2) | |
sudo pmset sleepnow | |
;; | |
3) | |
sudo shutdown -r now | |
;; | |
4) | |
echo "Operation aborted." | |
exit 1 | |
;; | |
*) | |
echo "Invalid option" | |
;; | |
esac | |
} | |
# Main script starts here | |
echo "Are you sure you want to perform this action? (yes/no, default: yes)" | |
read -r confirmation | |
confirmation=${confirmation:-yes} | |
if [[ $confirmation == "yes" ]]; then | |
display_menu | |
read -p "Enter your choice: " option | |
perform_action "$option" | |
# Check if the action was successful | |
if [[ $? -eq 0 ]]; then | |
echo "Action performed successfully." | |
else | |
echo "Error occurred while performing the action." | |
fi | |
else | |
echo "Operation aborted." | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Action Script | |
# Author: Felipe Alfonso González | |
# GitHub: github.com/felipealfonsog | |
# Contact: [email protected] | |
# License: BSD 3-Clause License | |
# Function to display the options menu | |
display_menu() { | |
echo "Select an option:" | |
echo "1. Shutdown" | |
echo "2. Suspend" | |
echo "3. Reboot" | |
echo "4. Abort" | |
} | |
# Function to perform the selected action | |
perform_action() { | |
choice=$1 | |
case $choice in | |
1) | |
sudo systemctl poweroff | |
;; | |
2) | |
sudo systemctl suspend | |
;; | |
3) | |
sudo systemctl reboot | |
;; | |
4) | |
echo "Operation aborted." | |
exit 1 | |
;; | |
*) | |
echo "Invalid option" | |
;; | |
esac | |
} | |
# Main script starts here | |
echo "Are you sure you want to perform this action? (yes/no, default: yes)" | |
read -r confirmation | |
confirmation=${confirmation:-yes} | |
if [[ $confirmation == "yes" ]]; then | |
display_menu | |
read -p "Enter your choice: " option | |
perform_action "$option" | |
# Check if the action was successful | |
if [[ $? -eq 0 ]]; then | |
echo "Action performed successfully." | |
else | |
echo "Error occurred while performing the action." | |
fi | |
else | |
echo "Operation aborted." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment