MySingleton.au3

MySingleton is a small function/include file I wrote to replace the Singleton UDF that comes with AutoIt.

Download

I was having issues with the original function on my laptop (it never returned False, meaning it never detected an existing script was running) so I wrote a quick and dirty replacement. Some of the other scripts I’ll be posting will require this include file so it’s just here for that purpose.

Download the MySingleton.au3 file, or copy the source below.

Func _MySingleton($sOccurrenceName, $iFlag = 0)
    ; Recently noticed _Singleton() never returns false on my laptop
    ; so I wrote this simple emulator using the old hidden window trick.
    Local $WTMM = Opt('WinTitleMatchMode', 3), $bReturn = False
    Local $sObfuscateWinTitle = 'MYSINGLETON:\' & $sOccurrenceName
    If Not WinExists($sObfuscateWinTitle) Then
        $bReturn = GUICreate($sObfuscateWinTitle)
    ElseIf $iFlag = 0 Then
        Exit -1
    EndIf
    Opt('WinTitleMatchMode', $WTMM)
    Return $bReturn
EndFunc
This entry was posted in AutoIt and tagged , . Bookmark the permalink.

Leave a Reply