auto Lock/Unlock mac if you are around

Discussion in 'Mac Programming' started by shaheen, Dec 28, 2013.

  1. shaheen macrumors newbie

    Dec 28, 2013
    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
    to lock:
    tell application "Finder"
    end tell

    to unlock:
    tell application "Finder"
    	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?
  2. chown33 macrumors 604

    Aug 9, 2009
    on the Western Slopes, with E. A. Poe
    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.)
  3. shaheen thread starter macrumors newbie

    Dec 28, 2013
    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.
  4. mrichmon macrumors 6502a

    Jun 17, 2003
    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.
  5. sliceoftoast macrumors 6502


    Mar 3, 2012
    In a Toaster
    There is another App on the Appstore called Token Lock Check it out here
  6. shaheen thread starter macrumors newbie

    Dec 28, 2013
    @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.
  7. mrichmon, Dec 30, 2013
    Last edited: Dec 31, 2013

    mrichmon macrumors 6502a

    Jun 17, 2003
    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.

Share This Page