Sign in to follow this  
Followers 0
trids

Multiple Instances Of The Same Script

11 posts in this topic

I have a particular script that I launch multiple times: each time with a different INI file. They don't all end at the same time, and sometimes I need to stop one instance while the others continue.

Instinctively, I would stop one by rightclicking on its System Tray icon and selecting Exit from the popup menu. But with multiple instances running - how can I find the right one? And how can I tell which ones remain after some have ended?

It would be great to be able to update the Tray Icon tooltip (ie: to display the name of the INI file) .. but that option is not available (... yet? :D ).

Any ideas anyone?

TIA

Share this post


Link to post
Share on other sites



AutoItSetTitle with a different name for each instance? :D

Share this post


Link to post
Share on other sites

Hmm, AutoItSetTitle does not affect the tray icon title......

MsgBox(4096,"","First Title")
AutoItWinSetTitle("One")

MsgBox(4096,"","Second Title")
AutoItWinSetTitle("Two")

MsgBox(4096,"","Third Title")
AutoItWinSetTitle("Three")

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

How about using a helper script that takes in the name of the ini file and then makes a copy of your "particular script" with a name similar to the name of the ini file, and then runs that copy.

The result should be a tray icon tip such as AutoIt - blah.ini.au3

EDIT: This seems to work :D

; Takes one paramter, your ini file:

$Script = 'C:\a particular script.au3'
$AutoIt = '"C:\Program Files\AutoIt3\AutoIt3.exe" '

If $CmdLine[0] < 1 Then Exit
$ini = $CmdLine[1]

$fileWithoutPath = StringSplit($ini, "\")
If Not @error Then
   $Renamed = $fileWithoutPath[$fileWithoutPath[0]] & '.au3'
Else
   $Renamed = $ini & '.au3'
EndIf
$x = FileCopy($Script, $Renamed)

Run($AutoIt & ' "' & $Renamed & '" "' & $ini & '" ')

;If your particular script is compiled, then simply say
;;;Run('"' & $Renamed & '" "' & $ini & '" ')
Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

Hmm,  AutoItSetTitle does not affect the tray icon title......

MsgBox(4096,"","First Title")
AutoItWinSetTitle("One")

MsgBox(4096,"","Second Title")
AutoItWinSetTitle("Two")

MsgBox(4096,"","Third Title")
AutoItWinSetTitle("Three")
at a time I think it did.

let have JON answer :D

Share this post


Link to post
Share on other sites

@ Sluggie: :D I love the way you think outside of the box! Nice trick - i'll give it a go.

@ jpm: thanks for the support, it would be nice to see it on the todo list :huh2:

Share this post


Link to post
Share on other sites

you could always run a script to check and close individual scripts.

Opt("TrayIconDebug", 1)
$x=Stringsplit("One,Two,Three",",")
for $i=1 to $x[0]
if WinGetState ($x[$i])<>0 then 
$test=msgbox(4,$x[$i]&" Currently running","Close this?")
if $test=6 then winclose($x[$i])
endif
next

; left code in so that you could use one script 
AutoItWinSetTitle("One")
MsgBox(4096,"","First Title")

AutoItWinSetTitle("Two")
MsgBox(4096,"","Second Title")

AutoItWinSetTitle("Three")
MsgBox(4096,"","Third Title")

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

what about traytip? you could set that to show based on the INI's name var, no?


"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

what about traytip?  you could set that to show based on the INI's name var, no?

Following up a bit on this idea. Make your script monitor a file somewhere (INI would be easy). You could use a second helper script to write something to the INI which will either:

1) Tell ALL instances of your script to display a brief TrayTip telling what they are.

2) Input some recognizable data that makes each instance different from one another (Such as the file name) and have the script with the matching file name display a traytip to point to the correct icon (Alternatively, it could close itself).

Share this post


Link to post
Share on other sites

Thanks Valik, but TrayTip() is only available for 2000/XP.

The best solution would be to edit the tooltip from the script (like Opt ("TrayIconDebug",1) almost does) .. which means a new intrinsic / built-in function I guess ( :D ).

Meantime, I've got a working work-around using Sluggie's idea of spawning renamed clones (Hmmm .. does this make me a virus-writer??? :huh2: )

Still holding thumbs for the ultimate solution though - a new intrinsic function .. oh wait, did I mention that already? :)

Share this post


Link to post
Share on other sites

One other thought is to set up individual closes. if you know the ini file, set up hotkeys acording to them.

ex.

!1 is for the first

!2 is for the second

!3 is for the third.

Or, have them all read an ini file via the adlib function, and display a tooltip if it exists, and close if it has there INI file in it.

AdlibEnable ("test")
; blah blah blah
 
func test()
if FileExists ( "c:\iniread.ini" ) then 
tooltip("something"), put a random locaion for them if you wish
$_x=FileRead ( "c:\iniread.ini", FileGetSize ("c:\iniread.ini"))
if stringinstr($_x,"testfile")>0 then exit; use a variable or such
endif
sleep(10)
endfunc

Anyway just showing there are many ways to acomplish the same thing.


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
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
Sign in to follow this  
Followers 0