Re: lock the screen from the keyboard, win a prize
Re: lock the screen from the keyboard, win a prize
- Subject: Re: lock the screen from the keyboard, win a prize
- From: Paul Skinner <email@hidden>
- Date: Sat, 23 Nov 2002 22:50:43 -0500
On Saturday, November 23, 2002, at 05:45 PM, John Delacour wrote:
At 12:20 pm -0500 23/11/02, Paul Skinner wrote:
snip
I actually prefer AppleScript. Verbose to the point of lucidity.
set previousState to SsaverPwordState({})
SsaverPwordState(1)
tell application "ScreenSaverEngine" to run
delay 5
SsaverPwordState(previousState)
on SsaverPwordState(parameter)
set {previousDelimiter, AppleScript's text item delimiters} to
{AppleScript's text item delimiters, ""}
set macAddress to (words 2 thru -1 of (do shell script "ifconfig en0
| grep ether")) as string
set preferenceFile to "" & POSIX path of (path to preferences as
string) & "ByHost/com.apple.screensaver." & macAddress
if parameter is not {} then
do shell script "defaults write " & preferenceFile & "
askForPassword " & parameter
end if
set PwordState to "defaults read " & preferenceFile & "
askForPassword "
set AppleScript's text item delimiters to previousDelimiter
return (do shell script PwordState) as integer
end SsaverPwordState
Yes that's, pretty concise
I take that as high praise considering the source. ; )
and it's good to pick up a couple more useful shell things. I'd trim
it to this, removing some unnecessary details:
set previousState to SsaverPwordState({})
SsaverPwordState(1)
do shell script "open -a ScreenSaverEngine"
delay 5
SsaverPwordState(previousState)
on SsaverPwordState(fl)
set ether to do shell script "ifconfig en0 | grep ether"
set en0 to "" & words 2 thru -1 of ether
set prefs to POSIX path of (path to preferences)
set plist to prefs & "ByHost/com.apple.screensaver." & en0
if fl is not {} then
do shell script "defaults write " & plist & " askForPassword " & fl
end if
set PwordState to "defaults read " & plist & " askForPassword "
do shell script PwordState
end SsaverPwordState
snip
JD
I was going to warn you about this breaking when the TIDs aren't set
to the default value. I realize now that this will never run in an
environment where the TIDs are not the default or where they need to be
reset. So I can trim it to this...
set previousState to SsaverPwordState({})
SsaverPwordState(1)
tell application "ScreenSaverEngine" to run
delay 5
SsaverPwordState(previousState)
on SsaverPwordState(parameter)
set preferenceFile to "" & POSIX path of (path to preferences) &
"ByHost/com.apple.screensaver." & (words 2 thru -1 of (do shell script
"ifconfig en0 | grep ether"))
if parameter is not {} then do shell script "defaults write " &
preferenceFile & " askForPassword " & parameter
return (do shell script "defaults read " & preferenceFile & "
askForPassword ")
end SsaverPwordState
--
Paul Skinner
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.