Jump to content

Exit Script after idle


Recommended Posts

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

  • Moderators

Bookman,

Look at _Singleton & _WinAPI_GetIdleTime in the Help file - that should get you started.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by Bookman
Link to comment
Share on other sites

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

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.
wend

kylomas

Edited 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

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

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...