Other Software > Developer's Corner
Autohotkey help
(1/1)
spazpunt:
Hi there :)
I have written a script which will basically number all open notepad windows or windows explorer windows as consecutive numbers depending on the order from topmost to bottommost, that is if it find a notepad it will be name 1 , another notepad 2, a window explorer 3
however i think that there is a problem with my ' if statement as it does not seem to recognise notepad or windows explorer could anyone please tell me what the problem is?
--- ---n=1
WinGet, id, list,,, Program Manager
Loop, %id%
{
this_id := id%A_Index%
WinGet, WinState, MinMax, ahk_id %this_id%
If ( WinState <> 0 )
titles := A_Index ; keep track of how many windows in list
WinGetTitle, titles%A_Index%, ahk_id %this_id% ; save original title
titles%A_Index% .= "`n" this_id ; and its ahk_id
WinGetTitle, this_title, ahk_id %this_id%
WinGetClass, this_class, ahk_id %this_id%
if this_class = Notepad,CabinetWClass
{
WinSetTitle,ahk_id %this_id%,, %n%
n := n + 1
}
MsgBox, 4, , Visiting All Windows`n%a_index% of %id%`nahk_id %this_id%`nahk_class %this_class%`n%this_title%`n`nContinue?
IfMsgBox, NO, break
}
msgbox, %titles%
; restore titles
Loop, %titles%
{
StringSplit, windowInfo, titles%A_Index%, `n
WinSetTitle, ahk_id %windowInfo2%,, %windowInfo1%
msgbox, %windowInfo2% %windowInfo1%
}
skwire:
You were very close. Change this line:
if this_class = Notepad,CabinetWClass
To:
if this_class in Notepad,CabinetWClass,ExploreWClass
Now it should do what you want. Alternately, you could do it this way:
If ( this_class = "Notepad" OR this_class = "CabinetWClass" OR this_class = "ExploreWClass" )
spazpunt:
thank you so much for your kind response 8)
:Thmbsup:
I really appreciate it
by the way althought I did put the line
--- ---WinGet, WinState, MinMax, ahk_id %this_id%
If ( WinState <> 0 )
at the beginning, it still renames all open windows even if they are minimised
skwire:
Two things:
1) If you don't want them renamed if they're minimised, use: If ( WinState <> -1 )
2) You're missing some braces (and this is where consistent indentation becomes important). Consider this:
--- ---n=1
WinGet, id, list,,, Program Manager
Loop, %id%
{
this_id := id%A_Index%
WinGet, WinState, MinMax, ahk_id %this_id%
If ( WinState <> 0 )
{
titles := A_Index ; keep track of how many windows in list
WinGetTitle, titles%A_Index%, ahk_id %this_id% ; save original title
titles%A_Index% .= "`n" this_id ; and its ahk_id
WinGetTitle, this_title, ahk_id %this_id%
WinGetClass, this_class, ahk_id %this_id%
if this_class in Notepad,CabinetWClass,ExploreWClass
{
WinSetTitle,ahk_id %this_id%,, %n%
n := n + 1
}
MsgBox, 4, , Visiting All Windows`n%a_index% of %id%`nahk_id %this_id%`nahk_class %this_class%`n%this_title%`n`nContinue?
IfMsgBox, NO, break
}
}
msgbox, %titles%
; restore titles
Loop, %titles%
{
StringSplit, windowInfo, titles%A_Index%, `n
WinSetTitle, ahk_id %windowInfo2%,, %windowInfo1%
msgbox, %windowInfo2% %windowInfo1%
}
spazpunt:
ok sir thank you managed to figure out the -1 thing b4 coming here :-[
Navigation
[0] Message Index
Go to full version