Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use Keychain Scripting to autocomplete certain logins Web Browsers
My bank thinks it knows better than me, and stops Safari from auto-completing my access details. There are ways around this, such as setting up a proxy to rewrite the bits of HTML and JavaScript on the page which prevent auto complete from working, but I wanted to try a different approach. I've never scripted the Keychain before, and along the way, I found a gotcha for those of you who might have tried before.

There is a bug in Keychain Scripting in Panther which makes it impossible to get any key values from a chain which contains a secure certificate. My bank makes me use one. The solution is to create a new separate keychain for AppleScript to use.
  1. Open Keychain Access and choose "New Keychain" from the File Menu.
  2. Give it a name like "ApplescriptKeys" or whatever you like.
  3. Create a new password item in your new keychain containing your bank login details. Username goes in the account box.
  4. Adjust the settings of the new keychain to whatever you like -- whether you want it to lock automatically, etc.
Now we're finished with Keychain Access. You now need to open Script Editor and paste this bit of code. Save the script to your ~/Library/Scripts folder as Bank Login.scpt, or whatever you like. Now you just navigate to the login screen at your bank's website, and run the script from the script menu.

Depending on your settings, you may be asked for your new keychain's password. It's up to you whether you always allow access for AppleScript to read this keychain. I just click Allow Once each time. It's still quicker than typing out my banking password. It also allows me to use a completely random password, and not even know what it is because the keychain will remember it for me. The usual security-related disclaimer applies, but seriously, once someone's logged in to your desktop, all bets are off anyway.

[robg adds: This worked quite nicely for me, and I found it easier to implement than the previous hint. It seems the scripting bug (feature) is still present in 10.4, though -- based on my brief testing, it looks like I'll need to create a new Keychain for each site I wish to access in this manner.]
    •    
  • Currently 2.67 / 5
  You rated: 4 / 5 (6 votes cast)
 
[14,073 views]  

Use Keychain Scripting to autocomplete certain logins | 9 comments | Create New Account
Click here to return to the 'Use Keychain Scripting to autocomplete certain logins' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use Keychain Scripting to autocomplete certain logins
Authored by: leenoble_uk on Nov 30, '05 07:47:18AM

I realised as soon as I submitted this that I had got bogged down in UI Scripting at one stage and the part which requires it is completely unnecessary. This piece of script stops UI Scripting being necessary if you want it to auto-submit:


do JavaScript "document.forms['" & theFormName & "'].submit();" in document 1

Place that after the other do Javascript lines if you want to avoid hitting return afterwards.

Also, I don't think you'd need a different keychain for each login. You can just add another key and adjust the script to use key 2 or something I'm sure. You could go one stage further and add a choice popup asking which key to use, though you might have to hardcode their names so you know what key 1 and key 2 are.

---
Brought to you by S C Johnson, a family multinational conglomerate.

[ Reply to This | # ]

Use Keychain Scripting to autocomplete certain logins
Authored by: thecloud on Nov 30, '05 12:00:12PM

You can look up a particular key in a keychain with a "whose" clause.

For example:
set theKey to first key of the current keychain whose server is "My Server"

You can narrow the search by combining attributes:
set theKey to first key of keychain "login.keychain" whose name is "www.macosxhints.com" and account is "thecloud"



[ Reply to This | # ]
Use Keychain Scripting to autocomplete certain logins
Authored by: BrentT on Nov 30, '05 09:01:23AM
I've had success by making a bookmarklet of the following javascript:
javascript:(function()%7Bvar%2520ca,cea,cs,df,dfe,i,j,x,y;function%2520n(i,what)%7Breturn%2520i+%2522%2520%2522+what+((i==1)?%2522%2522:%2522s%2522)%7Dca=cea=cs=0;df=document.forms;for(i=0;i%3Cdf.length;++i)%7Bx=df%5Bi%5D;dfe=x.elements;if(x.onsubmit)%7Bx.onsubmit=%2522%2522;++cs;%7Dif(x.attributes%5B%2522autocomplete%2522%5D)%7Bx.attributes%5B%2522autocomplete%2522%5D.value=%2522on%2522;++ca;%7Dfor(j=0;j%3Cdfe.length;++j)%7By=dfe%5Bj%5D;if(y.attributes%5B%2522autocomplete%2522%5D)%7By.attributes%5B%2522autocomplete%2522%5D.value=%2522on%2522;++cea;%7D%7D%7Dalert(%2522Removed%2520autocomplete=off%2520from%2520%2522+n(ca,%2522form%2522)+%2522%2520and%2520from%2520%2522+n(cea,%2522form%2520element%2522)+%2522,%2520and%2520removed%2520onsubmit%2520from%2520%2522+n(cs,%2522form%2522)+%2522.%2520After%2520you%2520type%2520your%2520password%2520and%2520submit%2520the%2520form,%2520the%2520browser%2520will%2520offer%2520to%2520remember%2520your%2520password.%2522)%7D)();
Drag the text to your Safari Bookmarks toolbar and give it a short name. I use "Remember". Fill out your bank site and select the bookmarklet before pressing the Submit button. You will get a popup telling you that the form values will be saved. Say OK then click the page's Submit button. The next time you return to the page you will see the form filled in. You obviously should only do this from your personal computer in a secured location.

[ Reply to This | # ]
Use Keychain Scripting to autocomplete certain logins
Authored by: eno on Nov 30, '05 09:20:58AM

Sounds great but doesn't work for me with Mac OS X 10.4.3, Safari 2.0.2 (416.13).



[ Reply to This | # ]
Use Keychain Scripting to autocomplete certain logins
Authored by: BrentT on Nov 30, '05 10:48:05AM

I do find that sometimes it doesn't work, but I haven't been able to figure out why. Most of the time it has worked for me. As they say: your mileage will vary.



[ Reply to This | # ]
Use Keychain Scripting to autocomplete certain logins
Authored by: badger brigade on Nov 30, '05 11:35:50AM
Use Keychain Scripting to autocomplete certain logins
Authored by: graemeaustin on Dec 09, '05 05:57:32AM

The original hint (with the extra line to get rid of the need for UI scripting) worked like a charm for me. Thanks very much for making my life that little bit easier (as I can never remember my bank enforced password and the bank's web site uses autocomplete=off).

For what it's worth, I couldn't get any of the other suggestions to work on my machine. Varying mileage I'm sure.

I'm running PowerBook G4 17" with OS 10.4.3 and Safari Version 2.0.2 (416.13) and Saft (but I'd be surprised if that makes a difference).

Graeme



[ Reply to This | # ]
Use Keychain Scripting to autocomplete certain logins
Authored by: chet on Feb 27, '06 08:56:03PM

Using the optional CamiTools preference pane in Camino 1.0, there is an option to "Ignore ‘autocomplete=off'" which makes Keychain Scripting unneccessary.

Chet



[ Reply to This | # ]
Use Keychain Scripting to autocomplete certain logins
Authored by: jeffreymellman on Mar 20, '07 04:07:07AM

you wrote:
Using the optional CamiTools preference pane in Camino 1.0, there is an option to "Ignore ‘autocomplete=off'" which makes Keychain Scripting unneccessary"

where is the optional cami preference pane?

(i'm using camino 1.0.4)
thanx--jeff



[ Reply to This | # ]