AppleScript, KeePassX and OSX

Oct 15,2017 at 12:51 pm By Ben Hutton

While there is no shortage of commercial solutions that will work on OSX I found open source solutions to be wanting. KeePassX while popular (at least is appears that way) works best under Linux. So the goal with this project was to get KeePassX and OSX working well together. To get KeePassX and OSX working well together requires a bit of coding.

I came late to using Password Managers.  I’ve had a history of creating a couple of really strong passwords that I use in multiple places. This has actually served me well however when I heard that LinkedIn had there password database leaked I decided it was time to review this. This was largely due to the realisation that I had the same password for Facebook.

AppleScript, KeePassX and OSX

The main reason I haven’t tried this in the past is largely due to trust. I don’t tend to trust other people with storing my passwords, especially closed source systems. I then did some research and came across KeePassX as probably the best alternative to a commercial solution. There was however a small issue with this. The auto-populated feature doesn’t work on OSX/MacOS. This is a bit of a deal breaker since it is my preferred platform.

After a bit more research into resolving this problem I came across a script written in AppleScript that solves the problem. Well at least it was supposed to.  I download it and found that it didn’t work on El Capitan. The plus side being a script I was able to debug it myself.

Getting the Script to work with El Capitan and Terminal

What I found by going through the script is that it was configured to work with iTerm2, which is a replacement to Terminal. I’m still using Terminal so I have reverted back to using that instead of iTerm2.  The next issue I found was that some websites didn’t work properly. They would open up to the login screen however the password would end up in the username box and nothing in the password box.

After looking at the non working pages I discovered that they don’t active the first element in the form. If you go to these pages you have to put your mouse pointer into the box and click before you can enter your username/password combination. To rectify this issue I added an option to activate the first input box on a login form. This resolved the issue.

Using the Script

All you need to do to get the script working is add the following commands into the URL box.

Using the Script

For sites that auto select the username field


For sites that do no


For example to use this with CloudFlare use the following:


Or with DigitalOcean use the following:



To download the source go to or type the following into a Terminal session:

git clone

Installing the script

Note: These instruction were copied and modified from

Download the file from the GitHub repository using the above command
Open Script Editor from Applications => Utilities, paste the content of into it and export it as ‘Application’, save it as somewhere on your disk.
With a text editor like ‘vim’, edit and set the content to “APPLokpx” (no double quotes). Edit and set the bundle signature to the last 4 letters of the value in PkgInfo file and add details about ‘kpx’ URL handling, you should get to something like this:
Note: CFBundleSignature should be there already, just update the string value. CFBundleURLTypes (and the array value) must be added.


Save the files you edited and the execute from Finder. This operation is registering the kpx URL handlers. The execution is practically exiting immediately, but afterwards Keepassx will be able to launch it for its registered URL schemes.

Leave a comment

Login to Comment

Copyright © 2017 | Ben Hutton