dimanche 8 mars 2015

How can I automate pasting of password into SecurityAgent?


On OS X 10.8.x I had an Automator service set up to paste a password from clipboard into the password window that pops up for mounting an encrypted disk.


I don't wish to store the password in my keychain, and it is long and tedious to type out.


I never got the applescript within the Automator service quite right. It would generate an error, but it still got the job done (i.e. the password was pasted). Since upgrading to Yosemite it seems the script in the Automator service doesn't work at all. The error generated indicates "window 1" doesn't exist.


Here is what I had:



tell application "System Events" to tell process "SecurityAgent"
set value of text field 1 of window 1 to (the clipboard)
if exists (text field 2 of window 1) then
set value of text field 2 of window 1 to (the clipboard)
end if
click button 1 of group 1 of window 1
end tell


I don't recall where I got this from, but some of it may have come from here


I know very little about AppleScript, and would appreciate some help fine tuning (or completely rewriting) this script so that it does the following:



  1. Checks there is data in the clipboard

  2. Checks the SecurityAgent window is active (or in some way ensures it can be interacted with, to avoid generating an error)

  3. Pastes the content of clipboard

  4. Clicks the 'Unlock' button


I don't know if it is possible, but it would be handy if it also brought 1Password to the foreground and activated "Copy password" (which is a menu option in the "Items" menu). I can, however, have Automator actions perform that task. But it would be nice to see (for learning) how to achieve that with AppleScript.





Aucun commentaire:

Enregistrer un commentaire