AHK integration of KeePass and IMacros

Post your working scripts, libraries and tools
j-t-r
Posts: 16
Joined: 08 Jun 2015, 03:05

AHK integration of KeePass and IMacros

04 Mar 2016, 03:38

AHK integration of KeePass and IMacros

Until imacros is integrated with keefox/keepass somehow I came up with simple solution bellow. Maybe it will be useful for you. See also:

Code: Select all

https://zohodiscussions.com/keefox#Topic/71684000000869005
https://sourceforge.net/p/keepass/discussion/329220/thread/05540762/?limit=25#a6eb
You need to select row/entry of site you want to sign-in in keepass and then press win + u:

Code: Select all

#u::
FileEncoding , UTF-8
winactivate, ahk_class WindowsForms10.Window.8.app.0.141b42a_r12_ad1
winwaitactive, ahk_class WindowsForms10.Window.8.app.0.141b42a_r12_ad1
clipboard =
send ^c
clipwait
pass = %clipboard%
ControlGet, outputvar, List, Selected, WindowsForms10.SysListView32.app.0.141b42a_r12_ad11, ahk_class WindowsForms10.Window.8.app.0.141b42a_r12_ad1
stringreplace,out,outputvar,%a_tab%,`r`n,A
name := TF_ReadLines(out, 1, 1, 1)
user := TF_ReadLines(out, 2, 2, 1)
note := TF_ReadLines(out, 5, 5, 1)
fileappend,"%user%"`r`n"%pass%"`r`n"%note%",D:\Apps\Firefox\Imacros\details.csv
sleep 1000
Run, C:\Program Files\Mozilla Firefox\firefox.exe imacros://run/?m=LOGINS`%5C%name%.iim
user =
pass =
note =
name =
return
It is persistent autohotkey (https://autohotkey.com/) script/code which:
1) runs the script when pressing win + u (since this script is persistent, you can run it as many times as you want; I also recommend to place shorcut of this script into C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup)
2) we will be "fileappending" file later and do not want it to be ANSI (since imacros does not like ANSI)
3) activates keepass window
4) waits till it is fully activated (it is to be sure that ctrl + c will be sent in the right window)
5) makes clipboard blank so we can use clipwait later
6) sends ctrl + c to keepass
7) waits for clipboard to be populated with password
8) populates variable pass before clipboard content (password) is deleted by keepass
9) retrieves selected row in keepass to variable outputvar (everything from name of entry to note except for password which is hidden using asterisks)
10) since these details are separated by tabs, we need to replace these tabs by new lines
11-13) reads these lines to corresponding variables (it needs a library from https://github.com/hi5/TF)
14) makes a csv file with needed details which will be used by imacros later
15) waits for one second
16) runs imacros login script from folder logins with the same name as entry in keepass
17-20) deletes variables with user details
21) ends autohotkey script

Imacros script then looks like this:

Code: Select all

URL GOTO=https://zohodiscussions.com/
FRAME F=1
SET !DATASOURCE details.csv
SET !DATASOURCE_LINE 1
SET !DATASOURCE_COLUMNS 1
WAIT SECONDS = 1
TAG POS=1 TYPE=INPUT:EMAIL FORM=ID:login ATTR=TYPE:email&&ONKEYPRESS:clearmsg()&&VALUE:&&CLASS:input<SP>usrbx&&ID:lid&&NAME:lid CONTENT={{!COL1}}
SET !ENCRYPTION NO
SET !DATASOURCE_LINE 2
SET !DATASOURCE_COLUMNS 1
WAIT SECONDS = 1
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ID:login ATTR=TYPE:password&&ONKEYPRESS:clearmsg()&&CLASS:input<SP>passbx&&ID:pwd&&NAME:pwd CONTENT={{!COL1}}
FILEDELETE NAME=D:\Apps\Firefox\Imacros\details.csv
WAIT SECONDS = 1
TAG POS=1 TYPE=BUTTON FORM=ID:login ATTR=CLASS:submit_mobile&&NAME:submit&&ID:submit_but&&TYPE:submit
This code would do this (you could record these macros by macro recorder and then adjust it to your needs):
1) loads zohodiscussions.com url
2) specifies frame for entering login details (not needed usually)
3) sets csv file with user details (from folder in settings/paths)
4-5) selects line which contains username
6) waits for one second
7) enters username in the sign-in form
8) see http://wiki.imacros.net/!ENCRYPTION
9-10) selects line which contains password
11) waits for one second
12) enters password in the sign-in form
13) deletes csv file with user details (without moving it to recycle bin)
14) waits for one second
15) submits user details

Voila! This can be easily used for sites which keefox/keepass fails to sign-in.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: aifritz and 57 guests