Jump to content

Active windows changing script


Recommended Posts

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
HotKeySet("{ESC}", "Terminate")     ;ESC terminates the script
HotKeySet("{F8}", "Restart")        ;F8 causes an Update of the FF-windows in max. 30 sec.

$aWL = WinList(" - Mozilla Firefox")
;$aWL = WinList(" - Internet Explorer")
While True
    For $i = 1 To $aWL[0][0]
        If Not IsArray($aWL) Then ExitLoop  ;Restarted or no FF-wondows
        if WinActivate($aWL[$i][1]) Then    ;only in existing windows
            Sleep(4000)
        Else    ;window is closed meanwhile
            ContinueLoop
        EndIf
    Next
    ;ConsoleWrite('Winlist Update'&@CRLF)
    $aWL = WinList(" - Mozilla Firefox")
WEnd

Func Restart()
    $aWL=''
    ConsoleWrite('Restarted'&@CRLF)
EndFunc

Func Terminate()
    Exit
EndFunc   ;==>Terminate

This code makes some windows poping againg in a row.  If I REM the line above WEnd, the windows are circulating regularly. The F8 part does not work then, but it is OK for me.

Link to comment
Share on other sites

Can you test this script:

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
HotKeySet("{ESC}", "Terminate") ;ESC terminates the script
HotKeySet("{F8}", "Restart") ;F8 causes an Update of the FF-windows in max. 30 sec.

$aWL = WinList(" - Mozilla Firefox")

While True
    While True
        For $i = 1 To $aWL[0][0]
            If Not IsArray($aWL) Then ExitLoop 2 ;Restarted
            If WinActivate($aWL[$i][1]) Then ;only in existing windows
                If IsArray($aWL) Then ConsoleWrite(@HOUR & ':' & @MIN & ':' & @SEC & ':' & @MSEC & @TAB & $aWL[$i][0] & ' activated' & @CRLF)
                Sleep(30000)
            Else ;window is closed meanwhile
                ContinueLoop
            EndIf
        Next
        ConsoleWrite(@HOUR & ':' & @MIN & ':' & @SEC & ':' & @MSEC & @TAB & 'Winlist Update' & @CRLF)
    WEnd
    $aWL = WinList(" - Mozilla Firefox")
WEnd

Func Restart()
    $aWL = ''
    ConsoleWrite(@HOUR & ':' & @MIN & ':' & @SEC & ':' & @MSEC & @TAB & 'Restarted' & @CRLF)
EndFunc   ;==>Restart

Func Terminate()
    Exit
EndFunc   ;==>Terminate

and if any miibehavings please post the output of scite output console. If no problems you can "REM" all lines starting with ConsoleWrite(....

Edited by AutoBert
Link to comment
Share on other sites

ah, that makes sense now. WinList returns the array in different order of elements each time, depending on which was last activated. you can sort the array after WinList, to make it more consistent:

#include <Array.au3>
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
HotKeySet("{ESC}", "Terminate") ;ESC terminates the script
HotKeySet("{F8}", "Restart") ;F8 causes an Update of the FF-windows in max. 30 sec.

While True
    $aWL = WinList(" - Mozilla Firefox")
    _ArraySort($aWL)
    For $i = 1 To $aWL[0][0]
        If Not IsArray($aWL) Then ExitLoop ;Restarted
        If WinActivate($aWL[$i][1]) Then Sleep(4000) ;only in existing windows
    Next
WEnd

Func Restart()
    $aWL = ''
    ConsoleWrite('Restarted' & @CRLF)
EndFunc   ;==>Restart

Func Terminate()
    Exit
EndFunc   ;==>Terminate

i truncated the entire If..Then...Else with the ContinueLoop, as it is not needed at all. think logically to understand why. i also repositioned the WinList call.

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

@orbs: the script does not show the windows at all. After F8 it goes to an error. I wonder what is wrong with the ArraySort

+>06:55:51 Starting AutoIt3Wrapper v.16.306.1237.0 SciTE v.3.6.2.0   Keyboard:00010405  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64  Environment(Language:0405)  CodePage:0  utf8.auto.check:4    # detect ascii high characters and if none found set default encoding to UTF8 and do not add BOM
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\chladekj\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\chladekj\AppData\Local\AutoIt v3\SciTE
>Running AU3Check (3.3.14.2)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\chladekj\Documents\Milan\Orbs1.au3
+>06:55:51 AU3Check ended.rc:0
>Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\chladekj\Documents\Milan\Orbs1.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
Restarted
"C:\Users\chladekj\Documents\Milan\Orbs1.au3" (9) : ==> Subscript used on non-accessible variable.:
For $i = 1 To $aWL[0][0]
For $i = 1 To $aWL^ ERROR
->06:56:08 AutoIt3.exe ended.rc:1
+>06:56:08 AutoIt3Wrapper Finished.
>Exit code: 1    Time: 17.44

 

@Autobert: your script works fine. If i close one window during the presentation, there is no need to F8.

>Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\chladekj\Documents\Milan\Autobert1.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
07:07:19:821    DMG MORI Messenger - Mozilla Firefox activated
07:07:23:157    Mapy.cz - Mozilla Firefox activated
07:07:26:533    Active windows changing script - AutoIt General Help and Support - AutoIt Forums - Mozilla Firefox activated
07:07:29:870    Google - Mozilla Firefox activated
07:07:33:262    (41) Facebook - Mozilla Firefox activated
07:07:36:266    Winlist Update
07:07:36:611    DMG MORI Messenger - Mozilla Firefox activated
07:07:39:948    Mapy.cz - Mozilla Firefox activated
07:07:43:307    Active windows changing script - AutoIt General Help and Support - AutoIt Forums - Mozilla Firefox activated
07:07:46:632    Google - Mozilla Firefox activated
07:07:50:145    (41) Facebook - Mozilla Firefox activated
07:07:53:152    Winlist Update
07:07:53:472    DMG MORI Messenger - Mozilla Firefox activated
07:07:56:866    Mapy.cz - Mozilla Firefox activated
07:08:00:217    Active windows changing script - AutoIt General Help and Support - AutoIt Forums - Mozilla Firefox activated
07:08:02:336    Restarted
07:08:03:729    Active windows changing script - AutoIt General Help and Support - AutoIt Forums - Mozilla Firefox activated
07:08:07:077    Mapy.cz - Mozilla Firefox activated
07:08:10:422    DMG MORI Messenger - Mozilla Firefox activated
07:08:13:792    Google - Mozilla Firefox activated
07:08:16:798    Winlist Update
07:08:17:143    Active windows changing script - AutoIt General Help and Support - AutoIt Forums - Mozilla Firefox activated
07:08:20:479    Mapy.cz - Mozilla Firefox activated
+>07:08:21 AutoIt3.exe ended.rc:0
+>07:08:21 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 62.42

 

 

Link to comment
Share on other sites

1 hour ago, Milan158 said:

... After F8 it goes to an error. I wonder what is wrong with the ArraySort ...

it's the restarting method, which  changes the data type of $aWL from an array to a string, on which _ArraySort can not operate. generally, changing the data type of a variable at run time is not a good idea. this works for me (including manually opening and closing Firefox windows at run time, with and without using the F8 key for restart):

#include <Array.au3>
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
HotKeySet("{ESC}", "Terminate") ;ESC terminates the script
HotKeySet("{F8}", "Restart") ;F8 causes an Update of the FF-windows in max. 30 sec.

Global $aWL[1][1]

While True
    $aWL = WinList(" - Mozilla Firefox")
    _ArraySort($aWL)
    For $i = 1 To $aWL[0][0]
        If $aWL[0][0]=0 Then ExitLoop ;Restart
        If WinActivate($aWL[$i][1]) Then Sleep(4000) ;only in existing windows
    Next
WEnd

Func Restart()
    $aWL[0][0]=0
    ConsoleWrite('Restarted' & @CRLF)
EndFunc   ;==>Restart

Func Terminate()
    Exit
EndFunc   ;==>Terminate

note that this Restart method simply places a zero where the windows count is to be found; and the condition in the For..Next loop checks for that.

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

@orbs : Thanks but does not work on my PC :(

I took the code from Autobert and tried to enhance it with inputbox and protection against a string input. Don't understand why the first IF does not work?

I miss the debugging of VisualBasic, steping the code row by row, reading the current values of variables, arrays, objects in any moment. Haven't found these possibilities in SciTE yet...

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
HotKeySet("{ESC}", "Terminate") ;ESC terminates the script
HotKeySet("{F8}", "Restart") ;F8 causes an Update of the FF-windows in max. 30 sec.

Global $SleepTime

$SleepTime=InputBox("input","set the changing period value in seconds",30)
If Not IsNumber($SleepTime) Then Terminate
$SleepTime=1000*$SleepTime

$aWL = WinList(" - Mozilla Firefox")

While True
    While True
        For $i = 1 To $aWL[0][0]
            If Not IsArray($aWL) Then ExitLoop 2 ;Restarted
            If WinActivate($aWL[$i][1]) Then ;only in existing windows
                If IsArray($aWL) Then ConsoleWrite(@HOUR & ':' & @MIN & ':' & @SEC & ':' & @MSEC & @TAB & $aWL[$i][0] & ' activated' & @CRLF)
                Sleep($SleepTime)
            Else ;window is closed meanwhile
                ContinueLoop
            EndIf
        Next
        ;ConsoleWrite(@HOUR & ':' & @MIN & ':' & @SEC & ':' & @MSEC & @TAB & 'Winlist Update' & @CRLF)
    WEnd
    $aWL = WinList(" - Mozilla Firefox")
WEnd

Func Restart()
    $aWL = ''
    ;ConsoleWrite(@HOUR & ':' & @MIN & ':' & @SEC & ':' & @MSEC & @TAB & 'Restarted' & @CRLF)
EndFunc   ;==>Restart

Func Terminate()
    Exit
EndFunc   ;==>Terminate

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...