AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Scripts within scripts

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Wed Nov 17, 2004 6:25 pm    Post subject: Scripts within scripts Reply with quote

Something I'd like to see is an enitre new functionality: scripts within scripts. What I mean is something like there's one universal parent script, which can contain any number of child scripts. (Am I using the right terminology here? Or is it master and slave in this case?) Each child script would be entirely self-contained and modular, unable to reach below into the parent script or to other child scripts. The parent script, in contrast, can affect all scripts, and can assign commands, menu items, hotkeys, etc. to suspend, edit, reload, and exit the child scripts. It would also be nice to have a default "Master control" gui. The parent script would be the only one with an icon in the system tray. Also, the parent script should have full script functionality, except for functions like ExitApp or Suspend that would have adverse effects.

The reason I mention this is that it would be endlessly useful to those of us with multiple scripts that like to integrate them for efficiency. This "parent" script would allow non-persistent scripts, separation of scripts, and the ability to still be able to pass commands like suspend, exit, etc.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Wed Nov 17, 2004 7:01 pm    Post subject: Reply with quote

That is interesting but it would probably a lot of code to implement. If anyone else has wished for such a feature, please post your comments here.

Until something like it gets done, you may know that some of it can already be done, albeit in a more clumsy way:

; To hide the icons for child scripts:
#NoTrayIcon

; To have parent close a child script:
DetectHiddenWindows, on
SetTitleMatchMode, 2
WinClose, MyScript.ahk - AutoHotkey

; To have parent suspend the hotkeys of a child:
DetectHiddenWindows, on
SetTitleMatchMode, 2
PostMessage, 0x111, 65305,,,MyScript.ahk - AutoHotkey

; To have a parent script close all children and optionally itself:
Code:
^!x::
; Close all other instances of AutoHotkey except this one:
DetectHiddenWindows, on
SetTitleMatchMode 2
Loop
{
   IfWinNotExist, - AutoHotkey v, , %A_SCRIPTFULLPATH%
      break
   WinClose
   WinWaitClose
}
; Now close this one:
ExitApp

If I left out anything you would like to be able to do right away, let me know since there might be some workaround.

Edit: Added SetTitleMatchMode 2 to the last script.


Last edited by Chris on Sat May 21, 2005 3:31 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Guest






PostPosted: Thu Nov 18, 2004 6:22 am    Post subject: Reply with quote

As with all things that I post before thinking about, this one has already been mostly done. Heh. Okay. I've got two approaches now, utilizing only existing code. The first includes it all in one script, and the second makes one master script control other scripts that are running.

This first one isn't very flexible at all, but it does put it all in one script. It also allows for the transformation of scripts, kind of like what you can do with XML using XSL.

Code:
A:
{
;  Insert script here.
}

B:
{
;  Insert script here.
}

C:
{
;  Insert script here.
}

#W::   ; This is for non-persistent scripts.
InputBox, RunScript, Run Script, Which child script should be run?
If RunScript =
return
Else
{
Gosub %RunScript%
return
}


This is one is quite flexible and uses a menu to control them. This could be changed to a gui. The downside is that this one requires extensive configuration just to simply add another script. If the concept interests you, I'll make a much more advanced version, that may allow adding a script without changing variables and structuring, and will have a configuration gui, and I'll give it it's own thread. However, I'd rather not take the effort if I'm way off base here. Feedback plz!

Code:
#Persistent
#SingleInstance
DetectHiddenWindows, on
SetTitleMatchMode, 2


; Once the script has been configured to handle a
; certain number of scripts, these variables are all
; that need to be changed.

Script1 = script1.ahk
Script2 = script2.ahk
Script3 = script3.ahk
Editor = notepad.exe

IfWinNotExist, %Script1% - AutoHotkey
Run, %Script1%

IfWinNotExist, %Script2% - AutoHotkey
Run, %Script2%

IfWinNotExist, %Script3% - AutoHotkey
Run, %Script3%

StringRight, Ext1, Script1, 4
StringRight, Ext2, Script2, 4
StringRight, Ext3, Script3, 4
StringTrimRight, Script1, Script1, 4
StringTrimRight, Script2, Script2, 4
StringTrimRight, Script3, Script3, 4


; Only thing that's wrong with this right now is
; there's no way to restart a script if it's exited.
; This, like many things, will be added if I remake
; the script.

Menu, tray, NoStandard
Menu, SuspendMenu, Add, &Suspend All, SA
Menu, SuspendMenu, Add
Menu, SuspendMenu, Add, &1 %Script1%, S1
Menu, SuspendMenu, Add, &2 %Script2%, S2
Menu, SuspendMenu, Add, &3 %Script3%, S3
Menu, tray, Add, &Suspend, :SuspendMenu
Menu, ReloadMenu, Add, &Reload All, RA
Menu, ReloadMenu, Add
Menu, ReloadMenu, Add, &1 %Script1%, R1
Menu, ReloadMenu, Add, &2 %Script2%, R2
Menu, ReloadMenu, Add, &3 %Script3%, R3
Menu, tray, Add, &Reload, :ReloadMenu
Menu, OpenMenu, Add, &1 %Script1%, O1
Menu, OpenMenu, Add, &2 %Script2%, O2
Menu, OpenMenu, Add, &3 %Script3%, O3
Menu, tray, Add, &Open, :OpenMenu
Menu, EditMenu, Add, &1 %Script1%, E1
Menu, EditMenu, Add, &2 %Script2%, E2
Menu, EditMenu, Add, &3 %Script3%, E3
Menu, tray, Add, &Edit, :EditMenu
Menu, ExitMenu, Add, Exit &Children, XC
Menu, ExitMenu, Add, Exit &Parent, XP
Menu, ExitMenu, Add, E&xit All, XA
Menu, ExitMenu, Add
Menu, ExitMenu, Add, %Script1%, X1
Menu, ExitMenu, Add, %Script2%, X2
Menu, ExitMenu, Add, %Script3%, X3
Menu, tray, Add, E&xit, :ExitMenu
Menu, tray, Add
Menu, tray, Add, &Window Spy, WS
Menu, tray, Add, &Text Editor, TE

StringReplace, Script1, Script1, %Script1%, %Script1%%Ext1%
StringReplace, Script2, Script2, %Script2%, %Script2%%Ext2%
StringReplace, Script3, Script3, %Script3%, %Script3%%Ext3%
return


SA:
PostMessage, 0x111, 65305,,,%Script1% - AutoHotkey
PostMessage, 0x111, 65305,,,%Script2% - AutoHotkey
PostMessage, 0x111, 65305,,,%Script3% - AutoHotkey
return

S1:
PostMessage, 0x111, 65305,,,%Script1% - AutoHotkey
return

S2:
PostMessage, 0x111, 65305,,,%Script2% - AutoHotkey
return

S3:
PostMessage, 0x111, 65305,,,%Script3% - AutoHotkey
return

RA:
PostMessage, 0x111, 65307,,,%Script1% - AutoHotkey
PostMessage, 0x111, 65307,,,%Script2% - AutoHotkey
PostMessage, 0x111, 65307,,,%Script3% - AutoHotkey
return

R1:
PostMessage, 0x111, 65303,,,%Script1% - AutoHotkey
return

R2:
PostMessage, 0x111, 65303,,,%Script2% - AutoHotkey
return

R3:
PostMessage, 0x111, 65303,,,%Script3% - AutoHotkey
return

O1:
PostMessage, 0x111, 65300,,,%Script1% - AutoHotkey
return

O2:
PostMessage, 0x111, 65300,,,%Script2% - AutoHotkey
return

O3:
PostMessage, 0x111, 65300,,,%Script3% - AutoHotkey
return

E1:
PostMessage, 0x111, 65304,,,%Script1% - AutoHotkey
return

E2:
PostMessage, 0x111, 65304,,,%Script2% - AutoHotkey
return

E3:
PostMessage, 0x111, 65304,,,%Script3% - AutoHotkey
return

XC:
PostMessage, 0x111, 65307,,,%Script1% - AutoHotkey
PostMessage, 0x111, 65307,,,%Script2% - AutoHotkey
PostMessage, 0x111, 65307,,,%Script3% - AutoHotkey
return

XP:
ExitApp

XA:
PostMessage, 0x111, 65307,,,%Script1% - AutoHotkey
PostMessage, 0x111, 65307,,,%Script2% - AutoHotkey
PostMessage, 0x111, 65307,,,%Script3% - AutoHotkey
ExitApp

X1:
PostMessage, 0x111, 65307,,,%Script1% - AutoHotkey
return

X2:
PostMessage, 0x111, 65307,,,%Script2% - AutoHotkey
return

X3:
PostMessage, 0x111, 65307,,,%Script3% - AutoHotkey
return

WS:
Run, C:\Program Files\AutoHotkey\AU3_Spy.exe
return

TE:
Run, %Editor%
return
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Thu Nov 18, 2004 1:33 pm    Post subject: Reply with quote

I don't think I would use it personally since I tend to put anything I use regularly into one big script. But I can see why this is something that might appeal to gamers or anyone who likes to have different sets of hotkeys depending on the type of task at hand.

Thanks for sharing it the initial version. Hopefully others will reply here if they have an interest.
Back to top
View user's profile Send private message Send e-mail
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Thu Nov 18, 2004 4:16 pm    Post subject: Reply with quote

I forgot to mention, that script works with compiled scripts too. As long as all the basic scripting functions (reload, exit) will work with the script, it can be controlled.
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5049
Location: imaginationland

PostPosted: Fri Nov 26, 2004 3:06 pm    Post subject: Reply with quote

The idea of scripts within scrips is a real good idea, it will make bigger tasks more easy to work with.
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Tue Dec 21, 2004 11:24 am    Post subject: Reply with quote

Very interesting concept. I like it.
Back to top
BoBo
Guest





PostPosted: Tue Dec 21, 2004 11:33 am    Post subject: Reply with quote

@ Guest
Which concept ? Not to use a nick ? Wink
Back to top
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Tue Dec 21, 2004 11:48 am    Post subject: Reply with quote

BoBo: speed-flamer extraordinaire Laughing
Back to top
View user's profile Send private message
Simpleton



Joined: 02 Nov 2004
Posts: 14

PostPosted: Sat Dec 25, 2004 10:51 am    Post subject: Reply with quote

What I do is #include all of my scripts into a master script. Each scripts has:
mk_PluginNumber++
mk_Plugin%mk_PluginNumber% = processkiller
processkiller_Title = Process Killer
along with some other configuration stuff, plus the actual script. The main script handles all of the actual hotkeys, along with changing (using a dialog box), disable/enable, and loading/saving the hotkeys to the registry.

Now its a lot more flexible, allows you to specify certain labels to call when it loads or saves, when a hotkey is changed, etc...

Anyways a similar approach could be taken to your second script.
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5049
Location: imaginationland

PostPosted: Mon Dec 27, 2004 5:50 pm    Post subject: Reply with quote

Scripts within scripts could be done with fileappend and dynamic commands Razz
Back to top
View user's profile Send private message Visit poster's website
FREAKKK
Guest





PostPosted: Wed Jan 26, 2005 5:46 pm    Post subject: Reply with quote

you could use include.. but then the problem would be that if you decided to compile your 'master' script.. all the included scripts at the time would be compiled during compilation (therefore you wouldn't be able to edit them (does that evan make sense? Smile ))
a workaround that i did was to compile autohotkey.exe in w/ the master script (via ifnotexist fileinstall...). then i set it up in my master script:
run, autohotkey.exe "%FILENAME%", , , %PIDVAR%"

the pid variables store all your pids of 'child' scripts, so your onexit just would Process, Close, %PROGNAME1%-- and then ifexist filedelete autohotkey.exe

now w/ the super-dooper gui features that autohotkey has-- it would be pretty easy to make your gui to help manage wich files to run/hotkeys/hotstrings.. or whatever

i've made an awesome little convient tool that i use at work to 1.) help prevent carpal tunnel & 2.) set me up in an environment that i can whip up quick little scripts on the fly (help me get stuff done quicker..)
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group