Robert Carnegie
Joined: 01 Jun 2005 Posts: 53 Location: Scotland
|
Posted: Sat Jul 09, 2005 12:51 pm Post subject: Developers, kill old ahk when you run new one: SingleVersion |
|
|
Robert actually finishes something, shock.
But I've forgotten, or forgotten where I put, or for some reason I am unable to use, my password to AutoHotkey.net .
SingleVersion 1.0.ahk is a little developer's tool - a script that can be #Include-d in any script you're working on whose name ends in numbers, such as Oedipus 0.5.ahk . SingleVersion will poll Oedipus's home directory for other files named "Oedipus *.ahk" and issue a WinClose message for each script found except for the current one. This means that when you run Oedipus 0.5 it will automatically kill Oedipus 0.4 - or any other. At least, that's the plan.
But remaining true to myself, there are enough missing features for me not to get around to - unless anyone wants to see them (or take the thing right off my hands). For instance, the script could have the effect that when Oedipus 0.4 is run, it detects that Oedipus 0.5 exists and asks whether you want to run that one instead. Or there could be a script that you tell to run Oedipus and it finds the latest version for itself, as well as killing other running versions. This'll do for now, though.
You also probably don't want to publish a script with SingleVersion.ahk still included - but that's up to you.
Come to think, what happens when you install a new version of AutoHotkey itself and you still have scripts running from the old one?
So here's Oedipus - try saving several versions:
| Code: |
#SingleInstance, Force
#Include, SingleVersion 1.0.ahk
DetectHiddenWindows, Off
SetTitleMatchMode, 1
Loop
{
Sleep 1000
}
|
And here's SingleVersion:
| Code: |
; SingleVersion 1.0.ahk
;
; AutoHotkey Version: tested on 1.0.36.01
; Language: English
; Platform: Win9x/NT
; Author: Robert Carnegie <rja.carnegie@excite.com>
;
; Script Function:
; Enforce #SingleInstance across multiple versions of an
; AHk script, by terminating any running script whose name
; differs from the desired script's only in a numeric
; version key, eg Oedipus 1.31.ahk. This allows a script
; developer conveniently to create and run a new version
; of a script file that automatically terminates any older
; version. It may be used by #Include in the desired script.
DetectHiddenWindows, On ; Allows a script's hidden main window to be detected.
SetTitleMatchMode, 2 ; Avoids the need to specify the full path of the file below.
Basename := A_ScriptName
StringRight, Cut, Basename, 4
If ( Cut = ".ahk" )
StringLeft, Basename, Basename, StrLen(Basename)-4
Loop
{
StringRight, Cut, Basename, 1
If ( InStr(".0123456789", Cut) )
StringLeft, Basename, Basename, StrLen(Basename)-1
Else
Break
}
SetWorkingDir, %A_ScriptDir%
Loop, %Basename%*.ahk
{
If ( A_LoopFileName <> A_ScriptName )
WinClose %A_LoopFileName% - AutoHotkey
}
; End of script
|
|
|