Jump to content

Simple Script to Script Communication

Recommended Posts

I search around the forum for a simple example of script to script communication, but could find an example I liked, so I thought I would write my own.

The end result is a script that I want to run as a context menu item in Explorer. I wanted to be able to only run one script when multiple files are selected and the context menu selected. Normally DDEExec is required to do this, which I don't think AutoIt can do. The result is a methodology that could be extended other type of script comms.

Basic operation is:

1. Instance 1 runs. As no other instance is running, the form is loaded. An invisible listbox exists on the form that will receive commands from other scripts.

2. Instance 2 runs. As another instance is running, a command is set to instance 1. Instance 2 then closes.

3. Instance 1 detects the command and processes it.

Hope someone else find it useful. This process also works if the form @SW_SHOW is disabled, for those that want a program without a GUI.


Opt("MustDeclareVars", 1)

#Include <GUIConstants.au3>

#Include <Misc.au3>

#Include <GuiList.au3>

Dim $Main_Form, $List1

Dim $File

Dim $ScriptName = StringLeft(@ScriptName, StringLen(@ScriptName) - 4)

If $CmdLine[0] = 0 Then ;No command line args

;Do nothing

Else ;Some command line args

$File = $CmdLine[1]


If _Singleton($ScriptName, 1) = 0 Then

$File = "Test.txt"

;Send the filename to the running instance

ControlCommand($ScriptName, "", "ListBox1", "AddString", $File)




#Region ### START Koda GUI section ### Form=F:\Programming\AutoIt Scripts\Inter-script Comms\Test Script.kxf

$Main_Form = GUICreate("Test Script", 236, 211, 215, 143, -1, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))

$List1 = GUICtrlCreateList("", 16, 16, 121, 110)

GUICtrlSetState(-1, $GUI_HIDE)


#EndRegion ### END Koda GUI section ###

WinSetTitle($Main_Form, "", $ScriptName)

Dim $msg

While 1

$msg = GUIGetMsg()

;Check for a new entry in the listbox

If _GUICtrlListCount($List1) > 0 Then

;Process the first entry in the listbox

ProcessNewFile(_GUICtrlListGetText($List1, 0))

;Remove the processed entry

_GUICtrlListDeleteItem($List1, 0)



Case $msg = $GUI_EVENT_CLOSE




Func ProcessNewFile($File)

MsgBox(0, "", $File)

EndFunc ;==>ProcessNewFile

“Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.”AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

Link to post
Share on other sites


Looks like a lot of potential!

Can you please do more examples?

Can it fill a huge listview while the script still is working?

What are the limitations?

What are the practical uses you would see?

thanks, Randall

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...