3

I'm wondering if there's a simple way to use one AppleScript program to turn something on and off. Basically I want it to do this.

Check current pmset sms
if sms = 0 
then 
   do shell script sudo pmset -a sms 1
if sms = 1
then 
   do shell script sudo pmset -a sms 0

How would I tell it to check the current value?

  • what is that a infinite loop ? – Ruskes Jun 1 '14 at 18:26
4

To get the state I would use something like:

set sms to (do shell script"pmset -g |grep \"sms\" | awk '{print $2}'")

Then:

if sms is "0" then
  do shell script"pmset -a sms 1" with administrator privileges
else
  do shell script"pmset -a sms 0" with administrator privileges
end if

Note the "administrator privileges" this is used because you will not be able to use 'sudo' because there will be no interface for you to type your password.

The "administrator privileges" will display a Normal OS Authentication dialogue for you to enter the user name and password.

0
set cur_state to do shell script "pmset -g" with administrator privileges
if cur_state = 1 then
    do shell script "pmset -a sms 0" with administrator privileges
else if cur_state = 0 then
    do shell script "pmset -a sms 1" with administrator privileges
end if
  • This will not work: do shell script "pmset -g" will return ALL settings – markhunte Jun 1 '14 at 20:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .