Bookman Posted July 28, 2015 Share Posted July 28, 2015 I have a script that's called by a DB program for using a barcode scanner. The script works fine, ut there are occasions where the user can sit idle for a while, then go back to scanning causing another iteration of the script running. Is it possible to have the script exit after a given idle time, or recognize that the script is already running and not load a second iteration? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 28, 2015 Moderators Share Posted July 28, 2015 Bookman,Look at _Singleton & _WinAPI_GetIdleTime in the Help file - that should get you started.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 Link to comment Share on other sites More sharing options...
Bookman Posted July 29, 2015 Author Share Posted July 29, 2015 (edited) I'm not a programmer, and it's been almost 10 years since I originally did this script (I'm old too!). It looks like _Singleton is the command I need, but I'm having trouble with the syntax. I just want only one instance of the script running. I would like it to simply not load if it is already running. The script I have just buffers the input of a barcode scanner to place it into a DB, so multiple iterations are a problem. The script I'm running is compiled (.exe) and distributed to other computers. Edited July 29, 2015 by Bookman Link to comment Share on other sites More sharing options...
xxaviarxx Posted July 29, 2015 Share Posted July 29, 2015 Maybe something like this it is a script to check if a window is running and if it is not running it will run the program via a desktop shortcut even if there is something full screen currently running. You could add in a loop function to constantly check to make sure it is running this is just a base code.Global $windowTitle = "insert name here" ; defines the window title for the script Global $shortcutTitle = "insert name here" ; defines the shortcut title for the script Global $checkWin = WinExists($windowTitle) ; sees if the window is open or not RunWindow() ; runs the RunWindow function Func RunWindow() ; runs the window If $checkWin = 0 Then ;0 = not launched/open ShellExecute($shortcutTitle, "", @DesktopDir) ; launches the window from your desktop $checkWin = 1 ; enables next block of code to activate EndIf If $checkWin = 1 Then ;1 = launched/open WinActivate($windowTitle) ; supposed to activate the window WinWaitActive($windowTitle) ; waits for the window to be active before continuing Sleep(10000) ; waits 10 seconds to make sure window is loaded fully EndIf EndFunc Link to comment Share on other sites More sharing options...
kylomas Posted July 29, 2015 Share Posted July 29, 2015 (edited) Bookman,Boiler plate of what M23 has suggested...#include <Misc.au3> #include <WinAPISys.au3> If _Singleton("MyDBUpdater", 1) = 0 Then exit msgbox(0,'','Update already running') while 1 if _WinAPI_GetIdleTime() > 1000*10 then exit msgbox(0,'','Idle time exceeded') ; 10 seconds, appx. wendkylomas Edited July 29, 2015 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Bookman Posted July 29, 2015 Author Share Posted July 29, 2015 This is far more in depth than I need. In my instance the script is called by a function in a Filemaker application. Once it is called it remains running in background. This is not a problem unless the user initiates the Filemaker script that calls the autoIt script again. The AutoIt script is simply a hotkey that opens a window to buffer input from a barcode scanner (Hot key definition, then several steps to gather the scanned info and send a command to the Filemaker appplication to trigger an action using the scanned info. Unfortunately, the AutoIt script will open multiple iterations causing problems. I'm looking for a command within the script that will check if there is a running iteration of the script and, if there is, not open another iteration. The alternative would be a script that I could call form the application to close the previous script. Link to comment Share on other sites More sharing options...
Bookman Posted July 29, 2015 Author Share Posted July 29, 2015 @kylomas, Thanks, The first line looks exactly like what I need. I don't even need the Msgbox.Thanks Link to comment Share on other sites More sharing options...
Bookman Posted July 29, 2015 Author Share Posted July 29, 2015 That's exactly what I needed, works perfectly! Thanks, All. Link to comment Share on other sites More sharing options...
kylomas Posted July 29, 2015 Share Posted July 29, 2015 You might want to change the 2ND parm of Singleton to "0". Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
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