AutoHotkey Community

It is currently May 27th, 2012, 8:07 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Scripts within scripts
PostPosted: November 17th, 2004, 6:25 pm 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2004, 7:01 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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 May 21st, 2005, 3:31 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 18th, 2004, 6:22 am 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 18th, 2004, 1:33 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 18th, 2004, 4:16 pm 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2004, 3:06 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
The idea of scripts within scrips is a real good idea, it will make bigger tasks more easy to work with.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 21st, 2004, 11:24 am 
Very interesting concept. I like it.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 21st, 2004, 11:33 am 
@ Guest
Which concept ? Not to use a nick ? :wink:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 21st, 2004, 11:48 am 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
BoBo: speed-flamer extraordinaire :lol:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 25th, 2004, 10:51 am 
Offline

Joined: November 2nd, 2004, 5:06 pm
Posts: 14
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 27th, 2004, 5:50 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Scripts within scripts could be done with fileappend and dynamic commands :P


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2005, 5:46 pm 
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? :-) ))
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..)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 27th, 2012, 8:05 pm 
Offline

Joined: November 22nd, 2009, 11:04 pm
Posts: 15
Scriptception ^^


sorry i just had to :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 27th, 2012, 9:01 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
You got it backwards, this topic (started in 2004) was the inception for the movie.

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 8 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group