Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Scripts to disable and enable password for lock screen after sleep or screen saver' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Scripts to disable and enable password for lock screen after sleep or screen saver
Authored by: steresi on Dec 08, '12 05:20:29AM

I would prefer a way to require a password only when waking from sleep, but never when turning off the screensaver. When my computer's awake, I'm in front of it or it's at home. It's when it's asleep in my bag that it could get stolen! Anyone know of something that can do this?

Scott



[ Reply to This | # ]
Scripts to disable and enable password for lock screen after sleep or screen saver
Authored by: BlackPenguin on Dec 09, '12 07:05:13AM
This certainly would be a desirable function. I'd suggest trying any one of a number of tools which allow you to run an AppleScript at sleep/wake, and then run one of the scripts above to turn on security at sleep and off at wake. Take a look at one of these:

Sleep Watcher
ConrolPlane (née Marco Polo)
How to Run an AppleScript on Wakeup with Power Manager ($$)

[ Reply to This | # ]
Scripts to disable and enable password for lock screen after sleep or screen saver
Authored by: JimGrisham on Feb 10, '13 08:41:13PM

This script monitors whether the computer is currently plugged in; I use it to keep my screensaver password off at home and turn it on automatically when I'm out. It should be run as a login item. It may not work for you, but it works for me on Mac OS X 10.8. If you use it as a login item, the "MonitoringStatus" variable at the beginning must be set to TRUE; as it is written below it will run once and then ask if you would like it to continue running.

If you run the script on a desktop computer (anything without a battery) it will toggle the current password setting and then quit. You can have this behavior on a laptop by setting the "ScriptToggleOnly" variable to TRUE at the beginning of the script.

The script is similar to those above and was based on one by Patrick Robinson that was found at <http://patjack.co.uk/toggle-screensaver-password-applescript/>.

- Jim Grisham

-----------------

-- MonitoringStatus should initally be 0 unless the script is to be run as a login item
-- (in that case, set it to "True")
set MonitoringStatus to 0
set CurrentStatus to 0

-- Set ScriptToggleOnly to "True" to run in toggle mode on laptops
set ScriptToggleOnly to false

repeat
-- We only want to notify users if we actually change anything
set NotificationRequired to false

-- Check if security preference pane is open so we can refresh it later
set CurrentPrefPane to 0
if application "System Preferences" is running then
tell application "System Preferences"
try
set CurrentPrefPane to get id of current pane
end try
end tell
end if

-- Check if computer is plugged in
set PowerStatus to do shell script "pmset -g | grep Battery"
if first character of PowerStatus is "B" then
set ComputerType to "Portable
else
set ComputerType to "Desktop"
end if
if last character of PowerStatus is not "*" then
set PowerStatus to "AC Power"
else
set PowerStatus to "Battery"
end if

tell application "System Events"
-- Verify Growl is running to prevent a "Select application" dialog when we request a notification later
set isGrowlRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0

-- Change password requirement rules
tell security preferences
if ComputerType is "Portable" then
-- on a laptop, require password when on battery power
if PowerStatus is "AC Power" then
if CurrentStatus is "activated" then set NotificationRequired to true
set require password to wake to false
set CurrentStatus to "de-activated"
else
if CurrentStatus is "de-activated" then set NotificationRequired to true
set require password to wake to true
set CurrentStatus to "activated"
end if
else
-- Toggle current password setting if this is a desktop computer
set NotificationRequired to true
if get require password to wake is true then
set require password to wake to false
set CurrentStatus to "de-activated"
else
set require password to wake to true
set CurrentStatus to "activated"
end if
end if
end tell

end tell

-- Display Growl notification of new status (notify the first time, even if status has not changed)
if NotificationRequired is true or MonitoringStatus is 0 then
tell application id "com.Growl.GrowlHelperApp"
set the allNotificationsList to {"Screensaver Setting"}
set the enabledNotificationsList to {"Screensaver Setting"}
register as application ¬
"Auto-lock toggle script" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "System Preferences"
notify with name ¬
"Screensaver Setting" title ¬
"Screensaver Setting" description ¬
"Passwords have been " & CurrentStatus & "." application name "Auto-lock toggle script"
end tell
end if

-- Refresh System Prefrences app if security pane is currently displayed
if CurrentPrefPane is "com.apple.preference.security" and NotificationRequired is true then
tell application "System Preferences"
set current pane to pane id "com.apple.preference.general"
set current pane to pane id "com.apple.preference.security"
end tell
end if

-- if not a laptop, we're done
if ComputerType is not "Portable" or ScriptToggleOnly is true then exit repeat

-- should we keep running? (we only ask this once)
if MonitoringStatus is not "True" then
if button returned of (display dialog "Run in background to continue monitoring power status?" default button 1) is not "OK" then exit repeat
set MonitoringStatus to "True"
end if

-- wait four minutes and then check again
delay 60 * 4
end repeat



[ Reply to This | # ]