I am trying to read and set disk and display sleep timer preferences (without opening the prefpane).
As a variation on what Kai teached us some time ago,
I am using
tell application "Finder" to set f to (name of startup disk & ":Library:Preferences:SystemConfiguration")
tell application "Finder" to set l to (folder f's files whose name starts with "com.apple.PowerManagement")
repeat with i in l
set p to (i as Unicode text)'s POSIX path
tell application "System Events" to tell property list item ¬
"\"Disk Sleep Timer\"" of property list file p to if exists then
if value is 0 then
set value to 180
else
set value to 0
end if
end if
end repeat
However, this fails as “"Disk Sleep Timer"” can not be found.
However, it is in the plist as can be checked with:
do shell script " defaults read /Library/Preferences/SystemConfiguration/com.apple.PowerManagement "
two reasons:
¢ a property list file in System Events has a “normal” path, not POSIX
¢ the nesting of property list items isn’t correct
This gets the value of Disk Sleep Timer
tell application "Finder" to set f to (name of startup disk & ":Library:Preferences:SystemConfiguration:com.apple.PowerManagement.plist")
tell application "System Events"
tell property list file f
get value of property list item "Disk Sleep Timer" of property list item 1 of property list item 1 of contents as integer
end tell
end tell
or much easier
last word of (do shell script "pmset -g disk | grep disksleep") as integer
to set disksleep you can use
set t to 180 as string
do shell script "pmset -a disksleep " & t with administrator privileges
Very good, thanks Stefan.
There is some discussion on what the “real” setting is, the pmset value or the "property list item “Disk Sleep Timer” that pmset occasionally seems write to on system events, but this will definitiely work for the time being.
Would you know what the parameter for System Sleep is…?
(this is different from disk sleep & display sleep!)