AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Script to Minimise All but Active Window

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
eXAKR



Joined: 24 Oct 2009
Posts: 4

PostPosted: Sat Oct 24, 2009 3:06 am    Post subject: Script to Minimise All but Active Window Reply with quote

So, a quick intro here: I'm eX.A.K.R., but you may also call me Alex if you wish.

Here's my problem: I have been trying to create a script for my Samurize config to minimise all but the active window. I had tried using VBScript in Windows Vista, but even with JSSys3.dll I couldn't get it to work. I then discovered AutoHotkey through the AeroShake script that was posted on LifeHacker, and decided that it had similar functionality as to what I need here. Trouble is, I have no idea how to port over the code in the AeroShake script to my own so that I can get it to run when I run the script "on demand" (i.e. when I run the script through my Samurize config). I do wonder if this is possible, and if not, if I can somehow elegantly duplicate this functionality.

Thanks for any help here.
Back to top
View user's profile Send private message
tekkie2412



Joined: 22 May 2007
Posts: 73

PostPosted: Sat Oct 24, 2009 4:14 am    Post subject: Reply with quote

Perhaps a little backwards, but works, and is quick

Code:

F1::
WinGetActiveTitle, current
WinMinimizeAll
WinActivate, %current%


F1 to activate
Back to top
View user's profile Send private message
Leef_me



Joined: 08 Apr 2009
Posts: 5336
Location: San Diego, California

PostPosted: Sat Oct 24, 2009 6:35 am    Post subject: Reply with quote

Here is a script that does it non-backwards Wink
Code:
F1::    ; hotkey is F1

WinGetActiveTitle, OutputVar

;modified from Winget Example #2: This will visit all windows on the entire system and display info about each of them:

WinGet, id, list,,, Program Manager
Loop, %id%
{
    this_id := id%A_Index%
    WinGetTitle, this_title, ahk_id %this_id%

    if (OutputVar = this_title)
    {
;   msgbox Active Window is %this_title%
    }
    else
    {
   winminimize %this_title%
    }
}
Back to top
View user's profile Send private message
eXAKR



Joined: 24 Oct 2009
Posts: 4

PostPosted: Sat Oct 24, 2009 6:43 am    Post subject: Reply with quote

Leef_me wrote:
Here is a script that does it non-backwards Wink
Code:
F1::    ; hotkey is F1

WinGetActiveTitle, OutputVar

;modified from Winget Example #2: This will visit all windows on the entire system and display info about each of them:

WinGet, id, list,,, Program Manager
Loop, %id%
{
    this_id := id%A_Index%
    WinGetTitle, this_title, ahk_id %this_id%

    if (OutputVar = this_title)
    {
;   msgbox Active Window is %this_title%
    }
    else
    {
   winminimize %this_title%
    }
}


I was about to say the previous one was not very elegant in doing it backwards, when you showed up. Thanks! Very Happy

By the way, what is the syntax for assigning a function to the Window + Home key combination (I do know the Window key is represented by "#")? Windows 7 has this shortcut key that does something similar, and I want to duplicate it on my Vista machine for now until I upgrade to 7.

Edit: the code doesn't seem to play nice with Samurize here. Any help for that?
Back to top
View user's profile Send private message
Leef_me



Joined: 08 Apr 2009
Posts: 5336
Location: San Diego, California

PostPosted: Sat Oct 24, 2009 7:20 am    Post subject: Reply with quote

Quote:
Edit: the code doesn't seem to play nice with Samurize here. Any help for that?
Sorry, can't offer any suggestions.

But since AutoHotkey comes alphabetically before Samurize, isn't it therefore better than Samurize? Wink
Back to top
View user's profile Send private message
eXAKR



Joined: 24 Oct 2009
Posts: 4

PostPosted: Sat Oct 24, 2009 7:37 am    Post subject: Reply with quote

Leef_me wrote:
Quote:
Edit: the code doesn't seem to play nice with Samurize here. Any help for that?
Sorry, can't offer any suggestions.

But since AutoHotkey comes alphabetically before Samurize, isn't it therefore better than Samurize? Wink


Heh Laughing .

Actually, what I'm trying to do here is to create a Samurize config that can interface with and minimise and restore all windows or just the inactive ones through a point-and-click interface (I flip between both the keyboard and mouse frequently, so it's best that I can configure both functions to be accessible through the keyboard and mouse).

In any case, is it actually possible to create a AutoHotkey script that runs itself?
Back to top
View user's profile Send private message
eXAKR



Joined: 24 Oct 2009
Posts: 4

PostPosted: Sun Oct 25, 2009 6:29 am    Post subject: Reply with quote

I decided to start thinking about this on my own and came up with some pseudocode:

Code:
; pseudocode for minorbutactivewindow script, accessible from an eg. Samurize config
Persistent

Run MinAllButActive

Function MinAllButActive
Activate TopMostWindow   ; Assume top-most window as last active window

Count UnMinimisedWindows
If UnMinimisedWindows > 1
   Enumerate ListOfUnMinimisedWindows
   Loop ListOfUnMinimisedWindows
      If Window on ListOfUnMinimisedWindows != ActiveWindow
         Minimise
         ListOfWindowsToRestore = ListOfUnMinimisedWindows
      End If
   Next
   Exit Function   ; Exit funtion once it exits from the loop
ElseIf UnMinimisedWindows = 1   ; Function used before, restore windows from saved list
   If ListOfWindowsToRestore > 0   ; Check if there's a list of windows to be restored
      Loop ListOfWindowsToRestore
         Restore
      Next
   Elseif ListOfWindowsToRestore = 0   ; No windows to restore
      Exit Function
   End if
   ListOfWindowsToRestore = 0
   Exit Function
ElseIf UnMinimisedWindows < 1       ; No windows
   ListOfWindowsToRestore = 0   ; User may have minimised or restored windows on his/her own, reset the script
   Exit Function
End If


As I am not well-versed in AutoHotkey scripting language at all though, I have no knowledge of porting this over to actual working code. Could someone look into my pseudocode above and see if it can be turned into real working code? Thanks.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group