Lock Keychain Applescript

Discussion in 'Mac Programming' started by pjrobertson, May 4, 2008.

  1. pjrobertson macrumors 6502a

    Joined:
    Nov 14, 2007
    #1
    So, here's the deal. I've copied an applescript seen here:

    http://safari.oreilly.com/1565928415/aplscptian-CHP-12

    The script is:

    tell application "Keychain Scripting" to lock

    I was hoping to add this to a quicksilver trigger to lock my 1Password keychain whenever I needed to.

    (I've tried the other method mentioned at O'Reilly;
    tell application "Keychain Scripting"
    if (not locked of keychain "1Password") then
    lock keychain "1Password"
    end if
    end tell

    but I get an applescript error "Can’t make locked of «class ckc » "MyPasses" of application "Keychain Scripting" into type boolean"
    )

    The first script I mentioned works half the time, but ONLY if the 'login' keychain is unlocked. If it's already locked, and I run the script, then none of the other keychains will be locked, but if it's unlocked and I run the script, then the login keychain will lock.

    Slightly strange behaviour, and I'm hoping someone here can shed some light on the situation, or come up with a better solution.
    I've added the keychain icon to the menu bar to lock the keychain from there, but I'd prefer a trigger / keyboard shortcut.

    Thanks
     
  2. roustk macrumors newbie

    roustk

    Joined:
    Jul 14, 2006
    #2
    I am not good at AppleScript at all but what if you use the "security" command-line utility directly:

    Code:
    security lock-keychain 1Password.keychain
     
  3. pjrobertson thread starter macrumors 6502a

    Joined:
    Nov 14, 2007
    #3
    Good idea!

    I added it as a trigger in quicksilver under the 'run in shell' command and it's working :D

    Thanks
     

Share This Page