grimmlock Posted January 29, 2013 Posted January 29, 2013 I have spent the past couple of days searching for the answer to this question, and I have not found one that really works. What I am trying to do, is have the following code always run and when ever notepad is open and idle for more then 2 seconds close it. It works but only when their is one instance of Notepad, if there are more then one it does not close all of them at the same time. Can someone help me, using this code, to have all windows with the title Notepad close? #include <Timers.au3> ;Declare the Timer: ; Global $TIMER = TimerInit() Opt("TrayOnEventMode",1) Opt("TrayMenuMode",1) HotKeySet("#{F4}", "_exit") ; Ctrl-Shift-Alt-X to exit While 1 ;If this application is active then reset the timer: If WinExists("Notepad") And _Timer_GetIdleTime() >= 2 * 1000 Then MsgBox (0, "Time reached", "You have been idle for more than 2 seconds.") WinClose("Notepad") EndIf ;Sleep for 1 seconds before looping again: ; Sleep(1000) WEnd Func _exit() Exit EndFunc Thanks Grimm Thanks Grimm
jazzyjeff Posted January 29, 2013 Posted January 29, 2013 Maybe use this instead: Run(@ComSpec & " /c taskkill /IM notepad.exe /F","",@SW_HIDE) I know it's more batch, but I believe this command typically kills all open instances. Perhaps a work around until you have a better solution.
grimmlock Posted January 29, 2013 Author Posted January 29, 2013 Thanks, that worked as a work around , still would like to close rather than kill ... Thanks Grimm Thanks Grimm
Moderators Melba23 Posted January 29, 2013 Moderators Posted January 29, 2013 grimmlock,Use WinList to get the handles of any open NotePad GUIs and then loop through the returned array using WinClose on each one. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
grimmlock Posted January 29, 2013 Author Posted January 29, 2013 Hiya Melba23, I copied this from the WinList function (Autoit), I am a little confused as to how to incorporate it . I do not see where I would put in "Notepad"? Local $var = WinList() For $i = 1 To $var[0][0] ; Only display visble windows that have a title If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1]) EndIf Next Func IsVisible($handle) If BitAND(WinGetState($handle), 2) Then Return 1 Else Return 0 EndIf EndFunc ;==>IsVisible Thanks Grimm
Moderators Melba23 Posted January 29, 2013 Moderators Posted January 29, 2013 grimmlock,You need to give a parameter to the WinListfunction so that it only lists Notepad GUIs. As you do not know the titles of all the GUIs, you need to look for the class - which you can get via the AutoIt Window Info Tool. WinList("[CLASS:Notepad]")All clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
grimmlock Posted January 29, 2013 Author Posted January 29, 2013 So I could use the above array just imply add Notepad in the $var=WinList(Notepad)? Thanks, Grimm Thanks Grimm
Moderators Melba23 Posted January 29, 2013 Moderators Posted January 29, 2013 grimmlock,$var=WinList(Notepad)That will not work - you need to use the correct syntax which I gave you in my last post. As you do not know the titles of the various Notepad GUIs, you need to use the class. Look in the Help file under <Using AutoIt - Window Titles and Text (Advanced)>. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
grimmlock Posted January 29, 2013 Author Posted January 29, 2013 I do know the title of the window "Polaris Shortcut Bar". My apologizes I forgot to include it. Thanks, Grimm Thanks Grimm
Moderators Melba23 Posted January 29, 2013 Moderators Posted January 29, 2013 grimmlock,Are all the Notepad instances titled the same? If so then by all means just use that. But why not use the class and make life simpler. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
grimmlock Posted January 29, 2013 Author Posted January 29, 2013 I think I got it Thank you Melba for all your help Grimm Thanks Grimm
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now