I'm trying to write an universal function for multiple similar tasks (run-or-raise an app). Here is an example of working code:
Code: Select all
SetTitleMatchMode, 2
#o::
AppsKey & o::
if WinActive( "Opera" )
{
; cycle through open windows
WinGetClass, CurrentActive, A
WinGet, Instances, Count, ahk_class %CurrentActive%
If Instances > 1
{
WinSet, Bottom,, A
}
WinActivate, ahk_class %CurrentActive%
}
else
{
; switch to the window or launch a new instance
if WinExist( "Opera" )
{
WinActivate
}
else
{
Run, "C:\Program Files\Opera\launcher.exe" --disable-update
}
}
return
Code: Select all
SetTitleMatchMode, 2
run_or_raise( name, exe )
{
global CurrentActive
global Instances
if WinActive( "%name%" )
{
; cycle through open windows
WinGetClass, CurrentActive, A
WinGet, Instances, Count, ahk_class %CurrentActive%
If Instances > 1
WinSet, Bottom,, A
WinActivate, ahk_class %CurrentActive%
}
else
{
; switch to the window or launch a new instance
if WinExist( "%name%" )
{
WinActivate
}
else
Run, %exe%
}
return
}
#o::
AppsKey & o::
run_or_raise( "Opera", """C:\Program Files\Opera\launcher.exe"" --disable-update" )
return