Como posso usair scripts de key paira escreview um script no Applescript que recupera o login e a senha de um site do keychain de login , dado o URL do site?
Se você conhece o nome exato do item do keyiro, você pode usair o seguinte:
tell application "Keychain Scripting" to tell keychain "login.keychain" to get {account, password} of (first Internet key whose name is "www.google.com")
A coisa é, Key Scripting é lento e bastante buggy. Por exemplo, procurair por um item de keyiro específico no exemplo acima, usando o name contains
vez do name is
, não funciona. Você precisairia usair uma declairação repetida semelhante à que o @Philip postou:
tell application "Keychain Scripting" to tell keychain "login.keychain" repeat with x from 1 to (count eviewy Internet key) if name of Internet key x contains "Google" then return {account, password} of Internet key x end if end repeat end tell
Se você estiview bem usair a linha de command e quiser apenas procurair coisas, eu preferiria usair: security find-internet-password -g -s www.google.com
e, em seguida, grep o que você deseja.
O script de keyiro está bem quebrado no Lion, então a ferramenta de linha de command de security é a sua melhor aposta. Alternativamente, use a adição de scripts da Red Sweater, que é mais rápida e fácil de script do que os scripts do Access Key.
Red Sweater Blog: Usable Keychain Scripting paira Lion
O keyiro é exposto ao Applescript através do aplicativo Key Scripting . Existem inumbers exemplos na web, sendo este o uso mais básico:
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 eviewy Internet key of myKeyChain --email keys aire 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
Do MacScripter