I have many simple scripts like key remapping and program launching. Is it possible to combine them in one script without this to cause conflict between them?
Because of these scripts i have lots of autohotkey.exe processes running in Task Manager, so i am wondering if i can reduce their number and probably reduce the ram usage.
How to combine multiple scripts in one?
- AfterLemon
- Posts: 85
- Joined: 30 Sep 2013, 14:27
- Location: Ohio, USA
Re: How to combine multiple scripts in one?
I'm not sure what to tell you here. Read some of the forum "Scripts" and see how they do it, test it yourself, give examples, and most of all... test test test. If something you're trying to combine does not work, try to figure out why and ask for help fixing it. Good luck!
HOME: Windows 11 Pro | AMD Ryzen 7 5800X 8-Core @ 4.50GHZ | 64GB RAM
MOBILE: Samsung Galaxy Note 10+
MOBILE: Samsung Galaxy Note 10+
- FanaticGuru
- Posts: 1905
- Joined: 30 Sep 2013, 22:25
Re: How to combine multiple scripts in one?
Generally where you get in trouble combining scripts is with the Auto-Execute section.
http://docs.ahkscript.org/Scripts.htm
Simple scripts are often just hotkeys without an Auto-Execute section. These can often be combined as long as you don't run into the second major problem which is Variables with the same name.
If you combine hotkeys what have variables with the same names you are probably going to have problems.
If you just want to eliminate tray clutter you can add #NoTrayIcon to the beginning of each script.
You can also use the script in my signature to launch multiply scripts and combine them into one tray icon.
These two methods will still have multiply processes running so will do nothing for ram usage but in my experience ram usage with AutoHotkey is insignificant even with a dozen scripts running compared to what other common processes are using.
Each Autohotkey script has about a 2 meg overhead. My Internet Explorer is using about 200 meg. I am currently using 2.61 gig total memory just with typical stuff open. So AutoHotkey's memory usage is just a drop in the bucket as far as I am concerned.
But if the scripts really are just a bunch of simple hotkeys I would want to combine them just for convenience of editing and running if nothing else.
FG
http://docs.ahkscript.org/Scripts.htm
Simple scripts are often just hotkeys without an Auto-Execute section. These can often be combined as long as you don't run into the second major problem which is Variables with the same name.
If you combine hotkeys what have variables with the same names you are probably going to have problems.
If you just want to eliminate tray clutter you can add #NoTrayIcon to the beginning of each script.
You can also use the script in my signature to launch multiply scripts and combine them into one tray icon.
These two methods will still have multiply processes running so will do nothing for ram usage but in my experience ram usage with AutoHotkey is insignificant even with a dozen scripts running compared to what other common processes are using.
Each Autohotkey script has about a 2 meg overhead. My Internet Explorer is using about 200 meg. I am currently using 2.61 gig total memory just with typical stuff open. So AutoHotkey's memory usage is just a drop in the bucket as far as I am concerned.
But if the scripts really are just a bunch of simple hotkeys I would want to combine them just for convenience of editing and running if nothing else.
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
-
- Posts: 60
- Joined: 03 Oct 2013, 19:49
- Location: Seattle Area
- Contact:
Re: How to combine multiple scripts in one?
I think the last post was correct. Memory usage is trivial, but it still is a lot nicer to have everything in one script. I have one script with a couple thousand lines that I keep running all the time, and I like that better than having a lot of small ones.
I would basically start with the biggest script you have, and then start merging the other small ones into. In practice it's usually easier than it sounds. Here's what you have to worry about:
I would basically start with the biggest script you have, and then start merging the other small ones into. In practice it's usually easier than it sounds. Here's what you have to worry about:
- The AutoExec section is everything before the first HotKey, HotString or function definition. This code is executed when the script starts, and then if there are any HotKeys, HotStrings the script stays resident.
- All of the AutoExec sections from all of your scripts have to be merged together.
- Any #include's in all of the scripts will have to be merged together. You can usually (but not always) put them in almost any order, and repeating the same one several times doesn't really heard anything so you don't have to be too fanatical about it.
- Any #If or #IfWinActive commands are effective until the end of the file. In practice this means that you will have to take all 'Global' HotKeys and put them at the top before the first #If… statement or at the bottom of a #If… Section, you can put a naked #If to restore global scope.
- Any global variables in the AutoExec section are super-global, meaning that they will automatically appear in any functions that have a variable with the same name. The vast majority of variables are just local variables and there is no real conflict. If you declare a variable in a function or HotKey section, most of the time you won't really have any problem. It's only globals that give you problems.
- #Includes
- AutoExec Section (including any global variables)
- Global Hotkeys/strings
- Hotkeys/strings with #If…
Re: How to combine multiple scripts in one?
Thanks, for the information!
- FanaticGuru
- Posts: 1905
- Joined: 30 Sep 2013, 22:25
Re: How to combine multiple scripts in one?
Variables declared in a HotKey section are not local and problems can occur if two hotkeys use the same variable.Wade Hatler wrote:If you declare a variable in a function or HotKey section, most of the time you won't really have any problem. It's only globals that give you problems. [/list]
Code: Select all
f1::
a := 5
return
f2::
MsgBox % a
return
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
-
- Posts: 60
- Joined: 03 Oct 2013, 19:49
- Location: Seattle Area
- Contact:
Re: How to combine multiple scripts in one?
DOH!! You're right ;)
- MilesAhead
- Posts: 232
- Joined: 03 Oct 2013, 09:44
Re: How to combine multiple scripts in one?
One thing you can do with a compiled script that may sit in the tray and be dormant is to call EmptyWorkingSet() API.
As soon as the script starts being invoked the OS allocates more resources. But if it's waiting for a key you may not press all day it might be worth the call.
Code: Select all
;call EmptyWorkingSet in AHK
_EmptyWorkingSet()
{
return DllCall("psapi.dll\EmptyWorkingSet", "UInt", -1)
}
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."
- MilesAhead
name on it and take the blame."
- MilesAhead
Re: How to combine multiple scripts in one?
From the sounds of it in this thread, there is no way to have a "global" variable that can be used in one script that contains multiple hotkeys. I use one script to run a bunch of different hotkeys that are located in the startup folder, and one of the things that I was hoping to do is assign a variable at the top of the script that has my password, then use that variable in multiple hotkeys.
- FanaticGuru
- Posts: 1905
- Joined: 30 Sep 2013, 22:25
Re: How to combine multiple scripts in one?
Your terminology is confusing to me.cws wrote:From the sounds of it in this thread, there is no way to have a "global" variable that can be used in one script that contains multiple hotkeys. I use one script to run a bunch of different hotkeys that are located in the startup folder, and one of the things that I was hoping to do is assign a variable at the top of the script that has my password, then use that variable in multiple hotkeys.
A script can have multiply hotkeys. Most variables in that script will be global. Meaning that a variable can be used in multiple places within that script.
You can have multiply scripts running (each script is a separate file). Normally two separate scripts do not share any variables or communicate in any way. Now there are ways to make two scripts communicate with each other but two separate scripts are as separate as any other two applications running on a computer.
"Hotkeys" are not located in the startup folder. "Scripts" that might contain "Hotkeys" are located in the startup folder.
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Re: How to combine multiple scripts in one?
Fair enough, perhaps I can rephrase and add some accuracy to my question.
I have a script that is compiled on the desktop with a shortcut in the startup folder.
That script has quite a few different hotkeys in it that I like to all have available while I am working.
I was hoping to assign a variable at the top of the script for my different passwords that I use for logging in to certain internal sites.
However, when I tried to do that by defining the variable at the top of the script like below (for example):
and then later in a script do something like this:
or maybe just
I have a script that is compiled on the desktop with a shortcut in the startup folder.
That script has quite a few different hotkeys in it that I like to all have available while I am working.
I was hoping to assign a variable at the top of the script for my different passwords that I use for logging in to certain internal sites.
However, when I tried to do that by defining the variable at the top of the script like below (for example):
Code: Select all
corppw = p@assword
Code: Select all
SendRaw, %corppw%
Code: Select all
Send, %corppw%
- FanaticGuru
- Posts: 1905
- Joined: 30 Sep 2013, 22:25
Re: How to combine multiple scripts in one?
It looks like you only have one script and what you seem to be describing should work.cws wrote:I have a script that is compiled on the desktop with a shortcut in the startup folder.
That script has quite a few different hotkeys in it that I like to all have available while I am working.
I was hoping to assign a variable at the top of the script for my different passwords that I use for logging in to certain internal sites.
Here is an actual working example:
Code: Select all
global corppw := "p@ssword"
F12::
Send % corppw
return
F11::
SendPassword()
return
SendPassword()
{
SendRaw % corppw
}
The global corppw := "p@ssword" needs to be near the top of the script before any hotkeys or returns.
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Who is online
Users browsing this forum: Google [Bot], iamMG, morkovka18, ntepa, william_ahk and 178 guests