danielchalmers / DesktopClock

A digital clock for your desktop!
https://github.com/danielchalmers
MIT License
137 stars 33 forks source link

Shortcut to close #58

Closed NotepadPlusUser closed 3 months ago

NotepadPlusUser commented 3 months ago

My vision is not too good. The Win shortcut to launch the Windows System Tray time and date is excellent because it disappears on the second press — except that I have to peer at it to read it.

I have downloaded your very flexible app, changed the colours and date-time format, and repositioned it over the System Tray. It's easy (using Directory Opus) to write a keyboard shortcut to launch it.

But how do I write a shortcut to close it (not hide it)? I often just want to read the date and/or time quickly for something that I am doing, and I certainly don't want to be fiddling about grabbing the mouse just to close it. The most straightforward way approach would be a parameter DesktopClock /x that would close it.

But the best solution would be DesktopClock /t that would toggle it on and off.

danielchalmers commented 3 months ago

Hi, thanks for the feedback! I wonder if a more suitable solution for you would be AutoHotkey.

Here's a script that will either launch the exe or close the "DesktopClock" window every time you hit Win+Shift+C:

; Trigger the script with Windows + Shift + C
#+c::

; Define the window title
windowTitle := "DesktopClock"

; Check if the window exists
IfWinExist, %windowTitle%
{
    ; Close the window if it exists
    WinClose, %windowTitle%
}
else
{
    ; If the window doesn't exist, launch the application
    Run, %localappdata%\DesktopClock\DesktopClock.exe
}
return

Let me know if that could work out!

NotepadPlusUser commented 3 months ago

Thank you very much @DanielChalmers. Yes, I already had a large number of AutoHotkey commands in a file that I run at every boot, so I simply added your code to it. I edited the path to desktop.exe and changed the trigger to Alt+Shift+D, and everything works fine.

I had already written two effective buttons in Directory Opus, killing the clock by: nircmd.exe exec hide taskkill /im DesktopClock.exe /t /f because without scripting, one can't easily check if a program is running. I had not thought to use AutoHotkey, so now I have just one button. Thank you.