Jump to content

Using Only One Instance Of Script


Recommended Posts

Hello

I associated a file extension with my script. The script processes something and then shows a tray menu which will stay for further options. When I call another file with the associated extension it will call another instance of my script. How to avoid this? I want that the already running instance will be used?

Some ideas?

Regards, Buffo

Link to comment
Share on other sites

Hello

I associated a file extension with my script. The script processes something and then shows a tray menu which will stay for further options. When I call another file with the associated extension it will call another instance of my script. How to avoid this? I want that the already running instance will be used?

Some ideas?

Regards, Buffo

Hi,

have a look at Singelton or at if ProcessExists() then ...

That will close the second one it a first exists.

Hope that helps.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Yes, I tried already ProcessExists() and _Singelton() but...

...how to close the new script that is checking if already an instance is running and give the parameters

to the old instance?

Link to comment
Share on other sites

I think I've seen UDFs on the type of inter-process communication you need.

One method is to create a gui with an input box and button. When second instance of script runs, it puts the command line info in the input box and clicks the button.

#include "Misc.au3"
#include "GuiConstants.au3"

Global $uniqueTitle = "UniqueTitle"

Opt("WinTextMatchMode", 1)
Opt("WinSearchChildren", 1)
Opt("WinDetectHiddenText", 1)

#NoTrayIcon

if _Singleton("myUniqueScript",1) = 0 Then
   ;Msgbox(0,"Warning","An occurence of test is already running")
    ControlSetText($uniqueTitle, "", "Edit1", $CmdLineRaw)
    ControlClick($uniqueTitle, "", "Button1")
    Exit
EndIf

Opt("TrayIconHide", 0);show tray icon

Opt("GUIOnEventMode", 1)

;Since @SW_HIDE didn't allow event to trigger, display window offscreen and without taskbar button
GuiCreate($uniqueTitle, 200, 50, -99999, -99999, $WS_POPUP, BitOR($WS_EX_TOPMOST,$WS_EX_TOOLWINDOW))
$input = GuiCtrlCreateInput("", 10, 10, 100, 20)
GuiCtrlCreateButton("Go", 150, 10, 20, 20)
GUICtrlSetOnEvent(-1, "InputFunc")
GuiSetState()
;GuiSetState(@SW_HIDE);Doesn't work

; Main body of script could go here
While 1
    sleep(10)
Wend

Func InputFunc()
    $value = GuiCtrlRead($input)
    GuiCtrlSetData($input, "")
    MsgBox(0x1000,"Info", $value)
EndFunc
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

@CyberSlug: That's a good idea. I didn't try but I think it will work.

But for my script it's much too complicated. Because my script consists of two different functions - to operate with given commandline parameters and to stay in tray - I seperate my script into two parts.

For the future another question: Is it possible to pass any data to a running script in a simple way? CyberSlug suggests the method with GUI, I think of a temporary file or a temporary environment variable. But that's not a simple way. I think of a function that checks if a process of the script is already running and if it's true the given parameters are bypassed to the running script and the other script will closed.

Perhaps you have some ideas :)

Regards,

Buffo

Link to comment
Share on other sites

@CyberSlug: That's a good idea. I didn't try but I think it will work.

But for my script it's much too complicated. Because my script consists of two different functions - to operate with given commandline parameters and to stay in tray - I seperate my script into two parts.

For the future another question: Is it possible to pass any data to a running script in a simple way? CyberSlug suggests the method with GUI, I think of a temporary file or a temporary environment variable. But that's not a simple way. I think of a function that checks if a process of the script is already running and if it's true the given parameters are bypassed to the running script and the other script will closed.

Perhaps you have some ideas :)

Regards,

Buffo

Hi,

maybe a totally stupid idea, but perhaps you can run a tcp-server and client and listen for messages as parameters.

So long,

Mega

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

*Lol*

It could be a little bit oversized for my project :)

Imagine:

You have written a notepad replacement and it's associated with

*.txt files.

If you doubleclick on an *.txt file your script will be started and shows

the file.

Now I doubleclick again on another *.txt file. No new instance of the script

should be started but the file should be shown in the old instance of the

script. That's all I want to (for example).

Now 2 solutions thinkable:

1. start new instance, check if already running, if it is, close the old instance and show the txt file. but how to differ old and new script to close

the right instance.

2. the script "realizes" that a new job is waiting for it. But how to realize that?

Regards,

Buffo

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