Posted on 12-09-2014 03:19 PM
Hey I found this recipe on GitHub by user cgerke. It's supposed to edit Energy Saver preferences, but I'm running into an issue where after executing the script I do not see any changes. The terminal window does not close out and I am unable to find any activity or trace of the script actually running in console. There's also the part where I'm not sure exactly how the script works. Some of the commands I've never seen before. If anyone could help me out that would be great. Below is the script.
#!/bin/bash
path_root="$3"; if [ -z "${path_root}" ] || [ "${path_root}" = "/" ]; then path_root=""; fi #++ fix //
formatted_date=$(date +"%Y%m%d%H%M%S") #++ date to string
if [ "${path_root}" != "/" ]; then
exit 1
else
pmset -a autorestart 0
pmset -a disksleep 0
pmset -a displaysleep 90
pmset -a powerbutton 0
pmset -a sleep 0
pmset -a womp 0
# Device Type
ioreg -rd1 -c IOPlatformExpertDevice | grep -E model | awk '{print $3}' | sed s/<"// | sed s/">// | grep "Book"
if [ "$?" == "1" ]; then
# Desktop
pmset repeat wakeorpoweron MTWRF 07:00:00 shutdown MTWRFSU 23:00:00
else
# Laptop
pmset -b autorestart 0
pmset -b disksleep 0
pmset -b displaysleep 90
pmset -b powerbutton 0
pmset -b sleep 120
pmset -b womp 0
pmset repeat shutdown MTWRFSU 23:00:00
fi
fi
exit 0
Posted on 12-10-2014 01:47 AM
The opening 'if' statements are the problem. What are you supplying to the script when you run it (not that it matters)? Not very helpful supplying no documentation in the script.
If $3 is empty then path_root will be empty. If path_root is empty, then the script will exit. If $3 is "/", then path_root will be set to an empty string again and so path_root again will be of a value that causes the script to exit.
In fact, path_root and formatted_date are useless in this script.
path_root="$3"; if [ -z "${path_root}" ] || [ "${path_root}" = "/" ]; then path_root=""; fi #++ fix //
formatted_date=$(date +"%Y%m%d%H%M%S") #++ date to string
if [ "${path_root}" != "/" ]; then
exit 1
So the script is basically always going to exit and never do it's intended job. Unless path_root is "/" then the rest of the script won't run and if path_root is "/" then it is changed to "", so the rest of the script won't run.
As for formatted_date, it isn't even referred to in the script.
I'd also ditch the ioreg command. It's not a very efficient way to find out if the model is a Laptop or not. Swap it out for:
getModel=`sysctl hw.model`
# This means, if getModel contains the string Book
if [[ "$getModel" =~ "Book" ]]
then
# Set laptop specific power options
fi
Posted on 12-10-2014 02:33 PM
What do you actually want to achieve?