Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

shaheen

macrumors newbie
Original poster
Dec 28, 2013
3
0
hello everyone,

is there anyway that i can auto lock/unlock your mac if you are around or not through a script.

knock to unlock did not fulfill my requirement, i want to automatically unlock my laptop if i am around and lock it when i move away.

through bluetooth it worked perfectly with locking/sleeping the laptop but i am facing difficulties to unlock when it wakes up.

application used: promixity
codes-
to lock:
Code:
tell application "Finder"
	sleep
end tell

to unlock:
Code:
tell application "Finder"
	launch
	tell application "System Events"
		tell application "System Events" to keystroke "PWD"
		tell application "System Events" to keystroke return
	end tell
end tell
unlock does not always succeed, any thoughts?
 
to unlock:
Code:
tell application "Finder"
	launch
	tell application "System Events"
		tell application "System Events" to keystroke "PWD"
		tell application "System Events" to keystroke return
	end tell
end tell
unlock does not always succeed, any thoughts?

Please explain what you expect this to do.

Are you expecting the Finder to act on the keystrokes "PWD" and return? If so, what do you expect to happen?

Since the Finder is normally always running, what do you expect the 'launch' command to do? (Since Finder is already launched, telling it to launch again serves no apparent purpose.)
 
Hi chown33,

if my computer lid is opened proximity should detect that my phone is around and it should tell finder to launch, it this case when it launches to wakes up the screen and enter my password PWD and send a return so that the computer is unlocked.

the above is my 1st interaction with coding or scripting or writing any sort of lines, so ease up on me and forgive my unawareness.
 
if my computer lid is opened proximity should detect that my phone is around and it should tell finder to launch, it this case when it launches to wakes up the screen and enter my password PWD and send a return so that the computer is unlocked.

There are a few apps available that do this. For example:

There is a lot more to getting bluetooth proximity detection working and hooking into system lock/unlock services securely than is going on in your AppleScript code snippets.
 
@sliceoftoast & mrichmon, thank you guys.. i went through them just before you've replied guys, thanks so much.. but i find it challenging to perform it through scripts as it is interesting to learn more about applescripts.

i also came through controlplane which is free and having variety of rules and conditions and as well may serve the purpose of what is required, but i am still looking for the code.
 
but i find it challenging to perform it through scripts as it is interesting to learn more about applescripts.

For your stated goal, of automatically unlocking your OS X laptop when you are nearby Applescript is by far the wrong language to use. Assuming that you are interested in implementing the functionality yourself you'll probably need to hook into the pam authentication services. One likely approach is to write your own pam handler as a shared library. But this kind of library is commonly implemented in C or C++ at a stretch rather than being anything that can be done in Applescript.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.