Jump to content

Recommended Posts

Posted
  On 5/30/2020 at 6:21 PM, argumentum said:

hmmm, let's say that I did not call the "Singleton_Delete($iSingleton)" and wanted to run the script again, how do I clear a previous $iSingleton ?

Expand  

You can use 

Global $iSingleton = Singleton()
Singleton_Delete(@extended)

to delete the atom.

But you cannot use this in you main script because how do you know if it was called the 1st time?

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

I always use this:

 

Global $sAppName = 'My App'

_RunOnce($sAppName, _OnSecondRun)
MsgBox(64, @ScriptName, 'Run me again')

;Main code...

Func _OnSecondRun()
    MsgBox(48, @ScriptName, 'Second copy detected, exiting...', 3)
    Exit
EndFunc

Func _RunOnce($sAppName = '', $sCallback = '')
    Local $iOld_WTMM = Opt('WinTitleMatchMode', 3)
    Local $sTitle = @ScriptName & '_@#$%^&*_' & $sAppName
    
    If WinExists('[CLASS:AutoIt v3;TITLE:' & $sTitle & ']') Then
        If Not $sCallback Then
            Exit
        EndIf
        
        Call(FuncName($sCallback))
    EndIf
    
    AutoItWinSetTitle($sTitle)
    Opt('WinTitleMatchMode', $iOld_WTMM)
EndFunc

You can use it even as UDF, without do anything...

RunOnce.au3:

#include-once
#OnAutoItStartRegister '__RunOnce'

Func __RunOnce()
    Local $iOld_WTMM = Opt('WinTitleMatchMode', 3)
    Local $sTitle = @ScriptName & '_@#$%^&*_' & @ScriptName
    
    If WinExists('[CLASS:AutoIt v3;TITLE:' & $sTitle & ']') Then
        MsgBox(48, @ScriptName, 'Second copy detected, exiting...', 3)
        Exit
    EndIf
    
    AutoItWinSetTitle($sTitle)
    Opt('WinTitleMatchMode', $iOld_WTMM)
EndFunc

Just add #include <RunOnce.au3> to your script.

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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
×
×
  • Create New...