topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday April 18, 2024, 1:38 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Autohotkey help  (Read 4984 times)

spazpunt

  • Participant
  • Joined in 2009
  • *
  • default avatar
  • Posts: 4
    • View Profile
    • Donate to Member
Autohotkey help
« on: August 02, 2009, 10:03 AM »
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

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: Autohotkey help
« Reply #1 on: August 02, 2009, 12:40 PM »
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" )
« Last Edit: August 02, 2009, 12:44 PM by skwire »

spazpunt

  • Participant
  • Joined in 2009
  • *
  • default avatar
  • Posts: 4
    • View Profile
    • Donate to Member
Re: Autohotkey help
« Reply #2 on: August 02, 2009, 01:32 PM »
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
« Last Edit: August 02, 2009, 01:38 PM by spazpunt »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: Autohotkey help
« Reply #3 on: August 02, 2009, 04:31 PM »
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

  • Participant
  • Joined in 2009
  • *
  • default avatar
  • Posts: 4
    • View Profile
    • Donate to Member
Re: Autohotkey help
« Reply #4 on: August 02, 2009, 05:55 PM »
ok sir thank you managed to figure out the -1 thing b4 coming here :-[