'How can I toggle an application in Auto Hot Key?

I want the app to open if not already open and minimize if it is already open with a single button. How can I do that?



Solution 1:[1]

Example:

F1::
    ; If !WinExist("WinTitle ahk_class WinClass", "WinText", "ExcludeTitlePart")
    If !WinExist("ahk_class Notepad") ; "!" means NOT in this case
        Run Notepad ; or Run Fullpath of your app
    else
        WinGet, WinState, MinMax, ahk_class Notepad
        {
            If WinState = -1 ; is minimized
                WinRestore
            else
                WinMinimize
        }
return

Use Window Spy to find the exact title, ahk_class, ahk_exe or text in the window of your app.

See WinExist, Run, WinGet etc. in the documentation.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user3419297