AHK to reopen closed program

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MatanCl
Posts: 10
Joined: 05 Jun 2021, 06:26

AHK to reopen closed program

Post by MatanCl » 23 Jan 2022, 14:11

Hi,

I have a script that closes a program:

Code: Select all

closeWin() {
   WinGet,AppName,ProcessName,A
   WinGet, active_id, ID, A
   WinClose, ahk_id %active_id%
   global closedWin := AppName
	Return
}
And I want to create an undo script for it, so I used a global variable called closedWin that I update in the first function:

Code: Select all

bringWinBack() {
   global closedWin
   Run, % closedWin
   Return
}
The thing is that my script does work - but not in the program I use the most: Visual Studio Code.

I guess it have something to do with "ahk_exe" which I have to use on other scripts when I want to execlude Visual Studio Code:

Code: Select all

#IfWinNotActive ahk_exe code.exe
But I don't know how can I fix it?

Thanks! :)

My whole code:

Code: Select all

global closedWin := "x"

^k::closeWin()

^+k::bringWinBack()

bringWinBack() {
   global closedWin
   Run, % closedWin
   Return
}
closeWin() {
   WinGet,AppName,ProcessName,A
   WinGet, active_id, ID, A
   WinClose, ahk_id %active_id%
   global closedWin := AppName
	Return
}

User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: AHK to reopen closed program

Post by mikeyww » 23 Jan 2022, 14:18

Code: Select all

^+k::Run, %app%
^k::
WinGet, app, ProcessPath, A
WinClose, A
Return

MatanCl
Posts: 10
Joined: 05 Jun 2021, 06:26

Re: AHK to reopen closed program

Post by MatanCl » 23 Jan 2022, 16:34

Thanks man! This worked perfectly! :bravo: :bravo: :bravo: :bravo: :bravo:

Post Reply

Return to “Ask for Help (v1)”