Rapid method to share between scripts ?

Get help with using AutoHotkey and its commands and hotkeys
Rayth
Posts: 11
Joined: 11 Mar 2017, 10:56

Rapid method to share between scripts ?

11 Mar 2017, 11:14

Hello,

I need to find the contents of a variable from another script. I found a long time ago on this forum the possibility to do it by adding this to my scripts:

objShell := ComObjCreate("WScript.Shell")
objEnv := objShell.Environment("Volatile")

Then using this format to read or write :
objEnv.Item("Test") := 1

It's ok, it works and I could do what I needed. However, if it works well for reading, this method is really slow for writing, it takes several seconds to change just a few variables.

Is there a faster method that allows me to realise this exchange of data between two scripts, or is it planned to improve this system ?
Guest

Re: Rapid method to share between scripts ?

11 Mar 2017, 11:22

Take your pick:

0. clipboard and/or hidden Gui
1. fileappend / fileread or iniwrite/read
2. same for dumping objects to files and read them back - https://github.com/ahkscript/awesome-Au ... ata-format
3. talk() https://autohotkey.com/board/topic/9432 ... -and-more/
4. OnMessage https://autohotkey.com/docs/commands/OnMessage.htm (working example posted)
5. .....
GEV
Posts: 844
Joined: 25 Feb 2014, 00:50

Re: Rapid method to share between scripts ?

11 Mar 2017, 11:53

What about IniRead and IniWrite?
Rayth
Posts: 11
Joined: 11 Mar 2017, 10:56

Re: Rapid method to share between scripts ?

11 Mar 2017, 12:05

Using an ini file requires reading and writing to the hard disk, I suppose that realize this very regularly and for a very long time must certainly be bad.

I prefer not to use this method and keep the work in RAM.
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

Re: Rapid method to share between scripts ?

11 Mar 2017, 12:33

PostMessage / SendMessage may work to send values to another script. If you need to receive them, you can send a "request" message. Or there's an inherent "reply" feature to Post/Send message, not sure. I know there is some distinction between them explained in the docs, but it might just be an "acknowledge" kind of like WinWaitClose after using WinClose.
Rayth
Posts: 11
Joined: 11 Mar 2017, 10:56

Re: Rapid method to share between scripts ?

11 Mar 2017, 12:49

Thank you, I did not know this method, I look if I can use it.
It seems rather complicated to use compared to objShell method. :/
Rayth
Posts: 11
Joined: 11 Mar 2017, 10:56

Re: Rapid method to share between scripts ?

12 Mar 2017, 07:49

Invité wrote:Take your pick:

0. clipboard and/or hidden Gui
1. fileappend / fileread or iniwrite/read
2. same for dumping objects to files and read them back - https://github.com/ahkscript/awesome-Au ... ata-format
3. talk() https://autohotkey.com/board/topic/9432 ... -and-more/
4. OnMessage https://autohotkey.com/docs/commands/OnMessage.htm (working example posted)
5. .....
Thanks !

After a few tries, the talk() function seems to me the simplest. It is also very fast execution. The examples on the site are no longer available, here is the simplest method I have find to make it work:

I need a master script, and several other scripts that perform tasks. The master retrieves data from all these scripts. Here with 2 senders only, a fast example :

Master.ahk :

Code: Select all

#Include talk.ahk
 
loop
{
	var1 := new talk("send1.ahk").getvar("var1")
	var2 := new talk("send2.ahk").getvar("test1")
	tooltip %var1% et %var2%
}
send1.ahk :

Code: Select all

#Include talk.ahk
new talk("Master.ahk")

loop
	random, var1, 0, 100
send2.ahk :

Code: Select all

#Include talk.ahk
new talk("Master.ahk")

loop
	random, test1, 0, 100
Master work only if sender1 and sender2 are already active, not know why.
FanaticGuru
Posts: 1497
Joined: 30 Sep 2013, 22:25

Re: Rapid method to share between scripts ?

13 Mar 2017, 16:18

Guest wrote:Take your pick:

0. clipboard and/or hidden Gui
This is a link to a hidden Gui solution:
https://autohotkey.com/boards/viewtopic.php?t=3275

It is not as technically sophisticated but it is simple and works.

It allows you to do GuiVar_Set("Customer","Fanatic Guru') in any script to set a value to "Customer" and then use GuiVar_Get("Customer") in any scripts to retrieve the value of "Customer".

Any script can use GuiVar_Set and GuiVar_Get to set and get the value of an AHK wide "variable".

Looking at this now I really should have used a class but I was not as keen on classes three years ago.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts

AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon

[Function] Timer - Create and Manage Timers
labedNadjib
Posts: 3
Joined: 16 Dec 2016, 18:40
Facebook: http://facebook.com/profile.php?id=100011403841640

Re: Rapid method to share between scripts ?

13 Mar 2017, 17:12

create a file(.txt for example) and you can write and read it by all scripts :)
Bones
Posts: 28
Joined: 30 Oct 2013, 15:30

Re: Rapid method to share between scripts ?

13 Mar 2017, 20:45

What about read/write to a RAMdisk?
Rayth
Posts: 11
Joined: 11 Mar 2017, 10:56

Re: Rapid method to share between scripts ?

14 Mar 2017, 13:50

FanaticGuru wrote: This is a link to a hidden Gui solution:
https://autohotkey.com/boards/viewtopic.php?t=3275

It is not as technically sophisticated but it is simple and works.

It allows you to do GuiVar_Set("Customer","Fanatic Guru') in any script to set a value to "Customer" and then use GuiVar_Get("Customer") in any scripts to retrieve the value of "Customer".

Any script can use GuiVar_Set and GuiVar_Get to set and get the value of an AHK wide "variable".

Looking at this now I really should have used a class but I was not as keen on classes three years ago.

FG
I try your solution, and it work really well, easy and fast execution, A little simpler to set up than talk().
thanks :)

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], denysy1, lblb, wineguy and 56 guests