Jump to content

Sending message from one Au3 script to a hidden Au3 script


Recommended Posts

I'm trying to write a script that will sit and wait for an event to happen. The event is triggered by an external application launching my script. (I've already figured out how to make sure the second instance of the script checks to see if the script is already running.) I want the new launching of the script to alert the waiting script to wake up and do something.

What means are available to send this "wake up" to the waiting script? I don't mind having a GUI button that it needs to press. But...

The waiting script normally has its window hidden. So, I don't think I can have my second copy press a button on the waiting copy, without unhiding the waiting copy, and moving the mouse (both unacceptable).

I see that there are these GUISendMsg and related functions, but if I'm not mistaken, I can only use that within the same copy of the script (i.e. only the waiting script can use it to control itself...the new copy of the script cannot use it to communicate with the waiting copy, right?)

I could use the old-fashioned method of just having the new copy write something to a file, and have the waiting copy poll the file every, say, 5 seconds and see if there's anything in it, and then wake up if there is. But I don't want to do that. I don't want my waiting script to access the hard drive all the time, thus keeping the drive from ever spinning down.

Basically I'm trying to come up with some basic inter-process communication. The root of my desire is that I have an external application that will launch any executable I want. At that moment, and only at that moment, I want an AutoIt script to take some action. But, I need at least one AutoIt script to sit and wait, always running, because in the event that two consecutive calls come from my external application, I do not want two separate AutoIt scripts running and yet I DO want my one AutoIt script to handle the pair of calls. So I need one always running that knows it's the one responsible for managing these incoming calls.

I've already figured out how to take that external application's call and use it to call my AutoIt script, which I'd like to then tell the already-running AutoIt script that it's time to take action.

I suspect there is a simple answer, and I can send a window event to my waiting, hidden script, that will effectively trigger the pressing of a button and thus come out of my GUIGetMsg loop - or that there is some other way to send and receive events between these two script instances.

Please let me know if my description is too complicated. :D

Thanks in advance for your help. This will be my first v3 script.

Link to comment
Share on other sites

I ought to say what my script's purpose is!

I'm trying to make a sort of pop-up balloon notifier for whenever I receive email that matches certain criteria. My email client matches on the criteria, but has no non-obtrusive visual way to alert me when this event occurs.

The intent of my script will be to pop up this little window that lists the name and subject of the sender. If multiple such messages come in before I take any action, this window will list all the messages. I can click in the window to either switch to (activate) my email client, or just ignore. Either way, the window will go away and the queue of notifications in this window will be cleared.

The pop-up window will be on top but will not receive the focus - so it won't interfere with whatever else I'm doing. And it won't bother coming up at all if it sees that I'm already working with my email client (i.e. it is active).

The way I've architected it, my email client calls my AutoIt script when a matching message comes in, and passes the Name and Subject as command-line parameters. The AutoIt script just appends that information into a text queue file. Then, if it sees that a waiting copy of the script is already running, it should tell that waiting copy to check the queue file for the new/added contents. If it sees that it's the only copy running, it becomes the waiting copy instead, after checking that queue file.

When I dismiss the window that will list the contents of the queue file to me, it will clear the file and hide the window (and possibly activate my email client window).

A lot of work for a little thing...but that's what we all do, right?

Thanks again for any suggestions.

Link to comment
Share on other sites

AutoItWinSetTitle() and WinSetTitle() and AutoItWinGetTittle()

Use the window title to pass data...

Thanks. I'm not sure I understand what you're getting at, though...yes, I can of course get the title of the waiting script (in fact, I already know it and use it to figure out whether I'm the only copy running or not). My question was: How can I communicate with the running script, short of making the window visible on screen and making the mouse move? I want to send a message to the running script while it's invisible.

I don't see any function that does that except one like GUICtrlSendMsg(), but it requires a "controlID", not a window title, and doesn't have any way to specify which window I'm talking about...presumably because it can only be used by a script itself, not by another script.

Am I missing something?

Thanks again...

Link to comment
Share on other sites

  • Moderators

There's several ways to do this, but the Control Functions (ControlGetText() etc...) require you to know the ControlID's and since your making the GUI, you should know them.

Another way is StderrRead/StdinWrite/StdoutRead etc.. in Beta, and yet another way is to figure out the Memory input.

Yes, all them require some work on your part for the coding, but here are examples of the 1st 2 (STD(s) **(Not Sexually Transmitted Disease)**, and Control Commands).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Aha, thanks, Larry! Clever - use the fact that you can change the title of another window as a means to send information to that other window.

Thanks again...the script is coming along nicely. I love AutoIt.

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