Skip to content

Instantly share code, notes, and snippets.

@gene-pavlovsky
Last active March 27, 2023 19:43
Show Gist options
  • Save gene-pavlovsky/97da0fa85bbf323fb8b0716991f1d558 to your computer and use it in GitHub Desktop.
Save gene-pavlovsky/97da0fa85bbf323fb8b0716991f1d558 to your computer and use it in GitHub Desktop.
EnvGet, ProgramFiles32, ProgramFiles(x86)
EnvGet, ProgramFiles64, ProgramFiles
if (!ProgramFiles32)
ProgramFiles32 := ProgramFiles64
; ************************************************************************************************************************************************************
; Run/show/hide KeePassXC using Win+K
;
#k::
if (WinExist("ahk_exe KeePassXC.exe") && WinActive("ahk_exe KeePassXC.exe"))
WinMinimize
else
Run % ProgramFiles64 . "\KeePassXC\KeePassXC.exe"
return
@gene-pavlovsky
Copy link
Author

Hi CerebralFreeze,

The EnvGet lines read Windows environment variables ProgramFiles(x86) and ProgramFiles, which have different values depending on whether your computer and/or Windows are 64-bit or 32-bit. These days it's getting less and less relevant as I suppose everyone runs 64-bit, but as a programmer I like to make things more compatible if it's not too much of a hassle.
https://stackoverflow.com/questions/9594066/how-to-get-program-files-x86-env-variable

Software being compiled for 32-bit or 64-bit is another thing, and my script doesn't do any auto-detection for this. I just use the right variable name depending on which version of which software I have installed (some only come in 64-bit or 32-bit, and some are available in both versions).

The error that you were having looks like the variables were not getting defined, which is weird.

There is nothing wrong with hardcoding the complete path, and I'm glad you figured it out and have it working.

I've recently had some issues with minimize working but activate/restore not. I don't know if it was caused by some KeePassXC update or something else, but it just wouldn't restore when "minimize to tray" option was activated. I didn't want to bother investigating it and just disabled minimizing to tray. It is a bit annoying, though. I wish KeePassXC adds this toggle window command-line option one day, which would make start/hide/show an AutoHotKey one-liner.

So far healthy, and doing my best to stay in shape. Exercise / play / red wine or beer is my recipe.

Cheers

@CerebralFreeze
Copy link

Gene,

To be honest, I'm a newb programmer so I don't know what the beginning section does or how the variables get defined later. So, I just wrote it the simple beginner way. You can change it back if you want. I just didn't know how to correct it.

Just to let you know, I haven't had any issues with active/restore after "minimize to tray" option was activated. So, I'm speculating the problem is related to the expert method you used.

Anyway, thanks again for the script. I appreciate it.

Enjoy the weekend!

@valner88
Copy link

What does this ahk script do??

@gene-pavlovsky
Copy link
Author

gene-pavlovsky commented Sep 14, 2021

@valner88 What is described in the comment on line 7 - runs, shows or hides KeePassXC (depending on it's current state), when you press Windows key and K simultaneously.

Similar to how (on Windows 7+) you can run/show/hide an app pinned to your taskbar by using Windows key and a corresponding digit 1-9.

I use various other similar shortcuts to make it quick to switch between commonly used apps. Some apps that hide to tray on minimize are a bit more tricky to unhide (WinExist returns false for the hidden window, you have to use some options like detect hidden windows etc), KeePassXC is actually one of them, I had a script that worked for a while but stopped working with another KeePassXC update, in the end I gave up and just disable the hide to tray option in it's settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment