키 체인 스크립팅을 사용하여 계정 및 비밀번호를 검색하는 AppleScript 사이트의 URL이 주어지면 로그인 키 체인 에서

키 체인 스크립트를 사용 하여 웹 사이트의 URL이 주어지면 로그인 키 체인 에서 웹 사이트의 로그인 및 비밀번호를 검색하는 스크립트를 AppleScript로 작성할 수 있습니까?



답변

키 체인 항목 의 정확한 이름 을 알고있는 경우 다음을 사용할 수 있습니다.

tell application "Keychain Scripting" to tell keychain "login.keychain" to get {account, password} of (first Internet key whose name is "www.google.com")

열쇠 고리 스크립트는 느리고 꽤 버그가 있습니다. 예를 들어 위의 예에서 특정 키 체인 항목을 검색하는 name contains대신 에을 사용하여 검색하면 name is작동하지 않습니다. @Philip이 게시 한 것과 유사한 반복 구문을 사용해야합니다.

tell application "Keychain Scripting" to tell keychain "login.keychain"

    repeat with x from 1 to (count every Internet key)
        if name of Internet key x contains "Google" then
            return {account, password} of Internet key x
        end if

    end repeat
end tell

명령 줄을 사용하고 물건을 찾길 원한다면, 나는 오히려 security find-internet-password -g -s www.google.com다음을 사용한다. 그리고 grep 을 사용하여 원하는 것을 찾는다
.


답변

키 체인 스크립팅은 라이온 (Lion)에서 꽤 잘 작동하므로 보안 명령 줄 도구가 최선의 방법입니다. 또는 기존 키 체인 액세스 스크립트보다 빠르고 쉽게 스크립트 할 수있는 Red Sweater의 스크립팅 기능을 사용할 수 있습니다.

레드 스웨터 블로그 : 사자 용 키 체인 스크립팅


답변

Keychain은 Keychain Scripting 응용 프로그램을 통해 Applescript에 노출됩니다 . 웹에는 가장 기본적인 사용법 인 수많은 예제가 있습니다.

set theShortUserName to do shell script "/usr/bin/whoami" --get the short
userid. This is how your default keychain is labled.

tell application "Keychain Scripting"
    set myKeyChain to keychain theShortUserName
    set theKeyList to every Internet key of myKeyChain --email keys are
normally Internet Keys
    repeat with x from 1 to (length of theKeyList)
        set theKey to item x of theKeyList
        if the name of theKey is "name of key here" then
            set thePassword to password of theKey --grab the password
            set theUserID to the account of theKey  --grab the userid
        end if
    end repeat
end tell

MacScripter에서