AHK Startup (Consolidate AHK Scripts' Tray Icons)

Post your working scripts, libraries and tools.
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

AHK Startup (Consolidate AHK Scripts' Tray Icons)

31 Aug 2023, 14:38

AHK Startup
for AutoHotkey v2

This is my startup script that I put a shortcut to run in my startup folder to load my standard scripts on computer bootup.

It basically Runs a list of scripts.
This list can include a folder which will run all files in that folder and subfolders. Wildcards * and ? can also be used.
Relative path can also be used by using .\ at the beginning of a file path. One dot is the folder this script is located in. Each additional dot steps back one folder.
It also looks for a txt file with the same name as the script and includes the files listed there.
It then creates a tooltip that list all the scripts that it started.
It then removes the tray icon of all the scripts it started leaving only the "AHK Startup" tray icon.
When AHK Startup is exited or stopped all the scripts it started will also be exited and stopped.

All the lines between:
(Join,

)]
Are example paths only to show different syntax and formatting of how paths can be done. These lines MUST BE EDITED to the path and scripts that the user wants AHK Startup to run.

In the list of scripts, the flag "/noload" can be used after a script name to not run the script but include it in the "Load" submenu. When a running script is exited through the menu then it is also moved to the "Load" submenu which means scripts can be loaded and unloaded through the menu by using "Load" and "Exit". I use "/noload" on scripts that I want easy access to but do not actually want to have running all the time. A script is only moved to the "Load" submenu if exited through the menu. If a script is closed directly or closes itself, then it is not added to the "Load" submenu.

Although this script is written in AutoHotkey v2, it can start both v1 and v2 scripts. The version needs to be specified in the list of scripts with the flags /v1 or /v2. If no version flag is present then /v2 is assumed. Alternatively, different extensions can be used for v1 and v2 scripts which then will be used to differentiate version (this is the approach I personal use with .ahk and .ah2 but is not the default for AutoHotkey).

May also need to adjust the paths for RunPathV1 and RunPathV2 if AutoHotkey is not installed to the default locations.

Everything that needs to be adjust should be in the INITIALIZATION - VARIABLES section.

I use this script for startup but AHK Startup does not really even have to be done at bootup, that is just how I use it. You could make three copies of AHK Startup and rename them "Work Scripts", "Web Scripts", and "Game Scripts". Then define within each of those which scripts it starts. Then run them as you need them, one or all three and have three tray icons that each start and stop related scripts together. AHK Startup is really about just consolidating multiply scripts to start and stop together like suites of scripts that you want to run together.

Code: Select all

; AHK Startup
; Fanatic Guru
;
; Version: 2023 09 26
;
; #Requires AutoHotkey v2
;
; Startup Script for Startup Folder to Run on Bootup.
;{-----------------------------------------------
; Runs the Scripts Defined in the Files Array
; Removes the Scripts' Tray Icons leaving only AHK Startup
; Creates a ToolTip for the One Tray Icon Showing the Startup Scripts
; If AHK Startup is Exited All Startup Scripts are Exited
; Includes a 'Load' menu for a list of scripts that are not currently loaded
; Includes flags to allow for running of both v1 and v2 scripts
;}

; INITIALIZATION - ENVIROMENT
;{-----------------------------------------------
;
#Requires AutoHotkey v2
#SingleInstance force  ; ensures that only the last executed instance of script is running
DetectHiddenWindows true ; scripts base window is generally hidden
;}

; INITIALIZATION - VARIABLES
;{-----------------------------------------------
; Folder: all files in that folder and subfolders
; Relative Paths: .\ at beginning is the folder of the script, each additional . steps back one folder
; Wildcards: * and ? can be used
; Flags to the right are used to indicate additional instructions, can use tabs for readability
; '/noload' indicates to not load the script initially but add to Load submenu
; '/v1' indicates to run with AutoHotkey v1 exe
; '/v2' or no version flag indicates to run with AutoHotkey v2 exe
Files := [	; Additional Startup Files and Folders Can Be Added Between the ( Continuations  ) Below
	(Join,
	"C:\Users\Guru\Documents\AutoHotkey\Startup\"
	"C:\Users\Guru\Documents\AutoHotkey\Compiled Scripts\*.exe"
	A_MyDocuments "\AutoHotkey\My Scripts\Hotstring Helper.ahk"
	"C:\Users\Guru\Documents\AutoHotkey\My Scripts\Calculator.ahk"	"/v2"
	".\Web\Google Search.ahk"	"/v1"
	"..\Dictionary.ahk"
	"Hotkey Help.ahk"
	"MediaMonkey.ahk"		"/noload"
	)]
	
; Define Path to AutoHotkey.exe for v1 and v2
; If ExtV1 and ExtV2 are different then the extension will be used to determine version
RunPathV1 := A_ProgramFiles '\AutoHotkey\AutoHotkey.exe'
ExtV1 := 'ahk'	; v1 extension
RunPathV2 := A_ProgramFiles '\AutoHotkey\v2\AutoHotkey.exe'
ExtV2 := 'ahk'	; v2 extension (personal use .ah2 for v2 scripts)
;}

; AUTO-EXECUTE
;{-----------------------------------------------
;
If FileExist(RegExReplace(A_ScriptName, '(.*)\..*', '$1.txt')) ; Look for text file with same name as script
	Loop Read RegExReplace(A_ScriptName, '(.*)\..*', '$1.txt')
		If A_LoopReadLine
			Files.Insert(A_LoopReadLine)

Scripts := Map()
For index, FileItem in Files
{
	(FileItem ~= '/noload' ? Status := false : Status := true)
	(FileItem ~= '/v1' ? RunPath := RunPathV1 : RunPath := RunPathV2)
	FileItem := Trim(RegExReplace(FileItem, '/noload|/v1|/v2'))
	If RegExMatch(FileItem, '^(\.*)\\', &Match)
		R := StrLen(Match[1]) ; Look for relative pathing
	Else
		R := false
	If (R = 1)
		FileItem := A_ScriptDir SubStr(FileItem, R + 1)
	Else If (R > 1)
		FileItem := SubStr(A_ScriptDir, 1, InStr(A_ScriptDir, '\', , , -(R - 1))) SubStr(FileItem, R + 2)
	If RegExMatch(FileItem, '\\$') ; If File ends in \ assume it is a folder
	{
		Loop Files FileItem '*.*', 'R' ; Get full path of all files in folder and subfolders
			Scripts_Push(A_LoopFileFullPath)
	}
	Else
		If RegExMatch(FileItem, '\*|\?') ; If File contains wildcard
		{
			Loop Files FileItem, 'R' ; Get full path of all matching files in folder and subfolders
				Scripts_Push(A_LoopFileFullPath)
		}
		Else
			Scripts_Push(FileItem)
}
Scripts_Push(Path)
{
	global RunPath
	SplitPath(Path, &Script_Name)
	If ExtV1 != ExtV2
		If (Script_Name ~= '\.' ExtV1 '$')
			RunPath := RunPathV1
		Else If (Script_Name ~= '\.' ExtV2 '$')
			RunPath := RunPathV2
	Scripts[Script_Name] := { Path: Path, Status: Status, RunPath: RunPath }
}

; Run All the Scripts with Status true, Keep Their Pid
For Script_Name, Script in Scripts
{
	If !Script.Status
		Continue
	; Use specific AutoHotkey version to run scripts
	; Required to deal with 'launcher' that was introduced when Autohotkey v2 is installed
	; Requires literal quotes around variables to handle spaces in file paths/names
	Run('"' Script.RunPath '" "' Script.Path '"', , , &Pid) ; specify Autohotkey version
	Scripts[Script_Name].DefineProp('PID', { Value: Pid })
}

OnExit(ExitFunc) ; Call ExitFunc when this Script Exits
TrayTipBuild(), MenuBuild()	; Build Menu and TrayTip
OnMessage(0x404, AHK_NOTIFYICON) ; Hook Events for Tray Icon (used for Tray Icon cleanup on mouseover)
OnMessage(0x7E, AHK_DISPLAYCHANGE) ; Hook Events for Display Change (used for Tray Icon cleanup on resolution change)
TrayIconRemove(10)	; Remove Tray Icons
;
;}-----------------------------------------------
; END OF AUTO-EXECUTE

; HOTKEYS
;{-----------------------------------------------
;
~#^!Escape:: ExitApp ; <-- Terminate Script
;}

; FUNCTIONS - GUI
;{-----------------------------------------------
;
MenuBuild()
{
	Menu_Load := Menu(), A_TrayMenu.Delete()
	For Script_Name, Script in Scripts
	{
		If Script.Status
		{
			Menu_Sub := Menu(), Menu_Sub.Pid := Script.Pid, Menu_Sub.Parent := Script_Name
			Menu_Sub.Add('View Lines', ScriptCommand)
			Menu_Sub.Add('View Variables', ScriptCommand)
			Menu_Sub.Add('View Hotkeys', ScriptCommand)
			Menu_Sub.Add('View Key History', ScriptCommand)
			Menu_Sub.Add('View Key History', ScriptCommand)
			Menu_Sub.Add()
			Menu_Sub.Add('Open', ScriptCommand)
			Menu_Sub.Add('Edit', ScriptCommand)
			Menu_Sub.Add('Pause', ScriptCommand)
			Menu_Sub.Add('Suspend', ScriptCommand)
			Menu_Sub.Add('Reload', ScriptCommand)
			Menu_Sub.Add('Exit', ScriptCommand)
			A_TrayMenu.Add(Script_Name, Menu_Sub)
		}
		Else
			Menu_Load.Add(Script_Name, ScriptCommand_Load)
	}
	A_TrayMenu.Add()
	A_TrayMenu.Add('Load', Menu_Load), A_TrayMenu.Default := 'Load'
	A_TrayMenu.AddStandard()
	Return
}

ScriptCommand(ItemName, ItemPos, MyMenu)
{
	Static Cmd := Map('Open', 65300, 'Reload', 65400, 'Edit', 65401, 'Pause', 65403, 'Suspend', 65404, 'Exit', 65405, 'View Lines', 65406, 'View Variables', 65407, 'View Hotkeys', 65408, 'View Key History', 65409)
	If (ItemName = 'Reload')	; if Reload, simulate by exiting and running again with captured Pid
	{
		try PostMessage(0x111, Cmd['Exit'], , , 'ahk_pid ' MyMenu.Pid)
		hWnds := WinGetList('ahk_pid ' MyMenu.Pid)
		For hWnd in hWnds
			Try WinKill('ahk_id ' hWnd)
		Run('"' Scripts[MyMenu.Parent].RunPath '" "' Scripts[MyMenu.Parent].Path '"', , , &Pid) ; specify Autohotkey version
		Scripts[MyMenu.Parent].Pid := Pid, MyMenu.Pid := Pid
		TrayIconRemove(6) ; need to remove new icon
	}
	Else
	{
		If (ItemName = 'Pause' or ItemName = 'Suspend')
			MyMenu.ToggleCheck(ItemName)
		try PostMessage(0x111, Cmd[ItemName], , , 'ahk_pid ' MyMenu.Pid)
	}
	If (ItemName = 'Exit')
	{
		hWnds := WinGetList('ahk_pid ' MyMenu.Pid)
		For hWnd in hWnds
			Try WinKill('ahk_id ' hWnd)
		Scripts[MyMenu.Parent].Status := false
		MenuBuild(), TrayTipBuild()	; Rebuild Menu and TrayTip
	}
}

ScriptCommand_Load(ItemName, ItemPos, MyMenu)
{
	Run('"' Scripts[ItemName].RunPath '" "' Scripts[ItemName].Path '"', , , &Pid) ; specify Autohotkey version
	Scripts[ItemName].Pid := Pid, Scripts[ItemName].Status := true	; keep new info

	MenuBuild(), TrayTipBuild()	; bebuild Menu and TrayTip
	TrayIconRemove(6) ; need to remove new icon
}
;}

; FUNCTIONS
;{-----------------------------------------------
;
TrayTipBuild()
{
	Tip_Text := ''
	For Script_Name, Script in Scripts
		If Script.Status
			Tip_Text .= Script_Name '`n'
	Tip_Text := Sort(Tip_Text)
	Tip_Text := TrimAtDelim(Trim(Tip_Text, ' `n'))
	A_IconTip := Tip_Text ; Tooltip is limited to first 127 characters
	Return
}

TrayIconRemove(Attempts)
{
	Global Scripts
	Loop Attempts	; try to remove over time because icons may lag especially during bootup
	{
		For Script_Name, Script in Scripts
			If Script.Status
			{
				hWnds := WinGetList('ahk_pid ' Script.Pid)
				For hWnd in hWnds
					KillTrayIcon(hWnd)
			}
		Sleep A_Index ** 2 * 200
	}
	Return
}

KillTrayIcon(scriptHwnd)	; converted from v1 code by Lexikos
{
	Static NIM_DELETE := 2, AHK_NOTIFYICON := 1028
	nic := Buffer(936 + 4 * A_PtrSize, 0)
	NumPut('UPtr', scriptHwnd, nic, A_PtrSize)
	NumPut('UInt', AHK_NOTIFYICON, nic, A_PtrSize * 2)
	Return DllCall('Shell32\Shell_NotifyIcon', 'UInt', NIM_DELETE, 'Ptr', nic)
}

TrimAtDelim(String, Length := 124, Delim := '`n', Tail := '...')
{
	If (StrLen(String) > Length)
		RegExMatch(SubStr(String, 1, Length + 1), 's)(.*)' Delim, &Match), Result := Match[] Tail
	Else
		Result := String
	Return Result
}

AHK_NOTIFYICON(wParam, lParam, uMsg, hWnd) ; OnMessage(0x404, AHK_NOTIFYICON) to cleanup tray icons on mouseover
{
	If (lParam = 0x200) ; WM_MOUSEMOVE := 0x200
		TrayIconRemove(1)
}

AHK_DISPLAYCHANGE(wParam, lParam, uMsg, hWnd) ; OnMessage(0x7E, AHK_DISPLAYCHANGE) to cleanup tray icons on resolution change
{
	TrayIconRemove(8) ; resolution change can take a moment so try over time
}

; Stop All the Scripts with Status true (Called When this Script Exits)
ExitFunc(ExitReason, ExitCode)
{
	For Script_Name, Script in Scripts
		If Script.Status
		{
			hWnds := WinGetList('ahk_pid ' Script.Pid)
			For hWnd in hWnds
				Try WinKill('ahk_id ' hWnd)
		}
	ExitApp
}
;}

The original v1 version of this script and discussion can be found here: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=788

FG
Last edited by FanaticGuru on 26 Sep 2023, 14:07, edited 4 times in total.
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
emp00
Posts: 165
Joined: 15 Apr 2023, 12:02

Re: AHK Startup (Consolidate AHK Scripts' Tray Icons)

31 Aug 2023, 14:57

"C:\Users\Guru\Documents\AutoHotkey\Startup\"
"C:\Users\Guru\Documents\AutoHotkey\Compiled Scripts\*.exe"
A_MyDocuments "\AutoHotkey\My Scripts\Hotstring Helper.ahk"
"C:\Users\Guru\Documents\AutoHotkey\My Scripts\Calculator.ahk" "/v2"
".\Web\Google Search.ahk" "/v1"
"..\Dictionary.ahk"
"Hotkey Help.ahk"
"MediaMonkey.ahk" "/noload"
Thanks @FanaticGuru - stupid question: Do you mind sharing the AHK scripts you're actually auto-starting? Looking at the names those sound very interesting and valuable for the community! :thumbup:
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: AHK Startup (Consolidate AHK Scripts' Tray Icons)

31 Aug 2023, 16:16

emp00 wrote:
31 Aug 2023, 14:57
Thanks @FanaticGuru - stupid question: Do you mind sharing the AHK scripts you're actually auto-starting? Looking at the names those sound very interesting and valuable for the community! :thumbup:

Here is my actual AHK Startup scripts:

Code: Select all

		'Quick Tools.ahk'
		'Google.ahk'
		'Hotkey Help.ahk'
		'Hotstring Manager.ah2'
		'Outlook.ahk'
		'Shortcuts.ahk'
		'Spelling Corrector.ahk'
		'..\Scripts\Compass.ahk' '/noload'
		'Fractions.ahk'
		'PRD Search.ahk' '/noload'
		'List Files.ahk'
		'AlwaysOnTop.ahk'
		'Independenator.ahk' '/noload'
I also independently startup:
  • Lintalist
  • Snipper
Many of these are somewhere on the forums but some are just too simple to really justify posting. But they are still super useful, like:

Code: Select all

#Requires AutoHotkey v1
#numpad0::	; <-- Open/Activate/Minimize Windows Calculator
{
	if WinExist("Calculator ahk_class CalcFrame") or WinExist("Calculator ahk_class ApplicationFrameWindow")
		if WinActive()
			WinMinimize
		else
			WinActivate
	else
		Run calc.exe
	return
}
This simple makes it where Win+Numpad0 opens, activates, or minimizes the calc.exe which is nothing fancy, but it made me get rid of my desktop calculator as now I can just hit Win plus the zero on the number pad to open a calculator, hit again to minimize, which is very intuitive and easy. I use it many times every day.

Maybe I will do one post that collects some of my smaller, but useful, scripts together.

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
emp00
Posts: 165
Joined: 15 Apr 2023, 12:02

Re: AHK Startup (Consolidate AHK Scripts' Tray Icons)

01 Sep 2023, 14:17

Thanks for these insights @FanaticGuru I'm very much interested in your above listed scripts "Here is my actual AHK Startup scripts"! It would be great if you could share them. Much appreciated!
JPMuir
Posts: 26
Joined: 06 Mar 2022, 07:31

Re: AHK Startup (Consolidate AHK Scripts' Tray Icons)

17 Sep 2023, 02:56

When I completed the configuration of files and paths, I received an error.
I've been using V1 currently without any problems, but v2 gives me the error I pictured.
image.png
image.png (24.34 KiB) Viewed 4841 times
image.png
image.png (70.26 KiB) Viewed 4841 times
I'm just not sure what to do at this point. Any guidance?
n00b
Posts: 29
Joined: 24 May 2016, 16:42

Re: AHK Startup (Consolidate AHK Scripts' Tray Icons)

22 Sep 2023, 13:04

same here
Image
if i remove all paths, no error pops up, but then no scripts are started ;)

Edit: I found the bug. :dance: If ExtV2 is set to ah2 then it works. The problem occurs If the extension is the same (ahk) for both v1 & v2.
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: AHK Startup (Consolidate AHK Scripts' Tray Icons)

22 Sep 2023, 18:20

n00b wrote:
22 Sep 2023, 13:04
same here
Image
if i remove all paths, no error pops up, but then no scripts are started ;)

Edit: I found the bug. :dance: If ExtV2 is set to ah2 then it works. The problem occurs If the extension is the same (ahk) for both v1 & v2.

Yes, the problem is that in the function Scripts_Push(Path) I assign what the RunPath is if ExtV1 and ExtV2 are not the same. But because I did an assignment to an existing variable somewhere in the function, it then made that a local variable that did not have the value of the same named global variable.

I believe just putting global RunPath at the top of the function should fix the problem. I could pass the RunPath as a parameter to the function to keep it local so the function does not change it but the only time it should get changed by the function is if ExtV1 and ExtV2 are not the same which then it should get change every time regardless of the flags.

This shows the nuance of v2 global/local in a function. RunPath := RunPathV1 both of these variables exist outside the function but RunPath in now a local version as it is being used in an assignment but RunPathV1 is global because of the way AHK v2 assumes a variable is global unless it is used in an assignment. The assignment never has to actually happen, the assignment just has to exist in the code to make a variable local.

Hopefully, this fixes the problem. It is hard for me to test as my setup uses the non-standard ahk and ah2 extensions.

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
n00b
Posts: 29
Joined: 24 May 2016, 16:42

Re: AHK Startup (Consolidate AHK Scripts' Tray Icons)

23 Sep 2023, 13:51

thanks for updating the script. It works now.

Edit: Reload a closed script leads to Error: Target window not found.
▶ 164: PostMessage(0x111, Cmd['Exit'], , , 'ahk_pid ' MyMenu.Pid)

BTW, V1 version of the script from 2023 03 16, works without error.
JPMuir
Posts: 26
Joined: 06 Mar 2022, 07:31

Re: AHK Startup (Consolidate AHK Scripts' Tray Icons)

23 Sep 2023, 14:02

☑ Yes, working now. Thanks FanaticGuru for digging out that solution. Wonderful application of Autohotkey for integrating multiple scripts in the desktop environment.
JPMuir
Posts: 26
Joined: 06 Mar 2022, 07:31

Re: AHK Startup (Consolidate AHK Scripts' Tray Icons)

23 Sep 2023, 14:09

to n00b, I tried to duplicate your error by closing some scripts within ahk_startup_v2 and reloading no error reported on my system. Mix of v1 and v2 scripts (8 total) all working as designed in the startup contained script.
n00b
Posts: 29
Joined: 24 May 2016, 16:42

Re: AHK Startup (Consolidate AHK Scripts' Tray Icons)

24 Sep 2023, 07:20

JPMuir wrote:
23 Sep 2023, 14:09
to n00b, I tried to duplicate your error by closing some scripts within ahk_startup_v2 and reloading no error reported on my system. Mix of v1 and v2 scripts (8 total) all working as designed in the startup contained script.
to reproduce the issue add this to your path:
"D:\msg1.ahk" "/v1"

msg1 code:
#Requires AutoHotkey v1.1.33+
msgbox,16 , AHK 1, This is a test.

run AHK Startup, a messagebox will pop up. press OK to close it.
-> right click, from the msg1.ahk menu select reload
-> Error: Target not found.
ozzii
Posts: 487
Joined: 30 Oct 2013, 06:04

Re: AHK Startup (Consolidate AHK Scripts' Tray Icons)

25 Sep 2023, 02:41

Surely because of the '1' in the file name.
Try with renaming your file.
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: AHK Startup (Consolidate AHK Scripts' Tray Icons)

25 Sep 2023, 12:24

n00b wrote:
24 Sep 2023, 07:20
JPMuir wrote:
23 Sep 2023, 14:09
to n00b, I tried to duplicate your error by closing some scripts within ahk_startup_v2 and reloading no error reported on my system. Mix of v1 and v2 scripts (8 total) all working as designed in the startup contained script.
to reproduce the issue add this to your path:
"D:\msg1.ahk" "/v1"

msg1 code:
#Requires AutoHotkey v1.1.33+
msgbox,16 , AHK 1, This is a test.

run AHK Startup, a messagebox will pop up. press OK to close it.
-> right click, from the msg1.ahk menu select reload
-> Error: Target not found.

You are attempting to reload a script that is not running. Reload is not a generic term for restarting a script, it is a specific command in AutoHotkey that reloads a currently running script. You could add Persistent at the top of the msg1.ahk script to keep it running.

It is possible the AHK Startup script could be altered so that if an attempt is made to Reload a script that is not running then the script would be Run instead. It seems I did that at one time but it caused another problem but I can't remember what that was.

AHK Startup has no good way to detect when a script it started closes on its own. In theory, it would be nice if a script closed itself, it would get moved from the 'Running' section of the tray menu to the 'Load' section. It would be fairly easy to do if I was willing to do it by polling all the scripts like once a second and see if they are still running but I don't like that approach. Another way would be with event hooks but that would add quite a bit of complexity to the code which is why I decided not to do it in the past and just accept that AHk Startup is designed for scripts that stay running. Another approach that I just thought of would be to detect if scripts are still running when the tray icon is moused over since I already added that detection to clean up stray icons that did not get hidden properly.

I will look into options further but till then you can just put Persistent in scripts.

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
n00b
Posts: 29
Joined: 24 May 2016, 16:42

Re: AHK Startup (Consolidate AHK Scripts' Tray Icons)

26 Sep 2023, 01:36

Tthanks FantaticGuru, for your time. The ahk v1 (not this one) of your startup script reloads my messagbox script "msg1.ahk" after closing it. I'm fine using that version. Thanks again.
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: AHK Startup (Consolidate AHK Scripts' Tray Icons)

26 Sep 2023, 14:14

n00b wrote:
26 Sep 2023, 01:36
Tthanks FantaticGuru, for your time. The ahk v1 (not this one) of your startup script reloads my messagbox script "msg1.ahk" after closing it. I'm fine using that version. Thanks again.

Added some Try and error handling in the script at top of thread.

It should now be able to handle attempting to Reload or Exit a script that has closed outside AHK Startup and is not currently running.

AHK v2 has more aggressive error reporting than AHK v1. AHK v1 would often just continue on when an error was encountered if possible. The v1 was encountering an error but it was just automatically being ignored by v1.

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
xavierarmand
Posts: 2
Joined: 18 Jan 2024, 16:02

Re: AHK Startup (Consolidate AHK Scripts' Tray Icons)

21 Jan 2024, 21:04

help!!! ive been trying for a couple hours to get his lauch. sometimes it will try to lauch the 6 scripts i put in it but everyone one of them is getting an error from AHK.

now i cant even get that far it keeps saying .....

Error: Unexpected "]"

Text: DetectHiddenWindows true C:\Users\CLxxxEN\Documents\AutoHotkey\AHKScriptHub\AHKS…
Line: 23
File: C:\Users\CLxxxEN\Documents\AutoHotkey\AHK_Startup.ahk
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: AHK Startup (Consolidate AHK Scripts' Tray Icons)

22 Jan 2024, 20:22

xavierarmand wrote:
21 Jan 2024, 21:04
help!!! ive been trying for a couple hours to get his lauch. sometimes it will try to lauch the 6 scripts i put in it but everyone one of them is getting an error from AHK.

now i cant even get that far it keeps saying .....

Error: Unexpected "]"

Text: DetectHiddenWindows true C:\Users\CLxxxEN\Documents\AutoHotkey\AHKScriptHub\AHKS…
Line: 23
File: C:\Users\CLxxxEN\Documents\AutoHotkey\AHK_Startup.ahk

That error is generally caused by a mismatch of opening brackets [ to closing brackets ].

You probably added or deleted a [ or ] somewhere, probably between line 35 Files := [ and its closing bracket ].

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
Jasonosaj
Posts: 56
Joined: 02 Feb 2022, 15:02
Location: California

Re: AHK Startup (Consolidate AHK Scripts' Tray Icons)

23 Jan 2024, 14:55

Has anyone found a way to add custom script menu items dynamically? in other words, if a script has custom traymenu entries, to incorporate those into the startup script submenu?
viv
Posts: 219
Joined: 09 Dec 2020, 17:48

Re: AHK Startup (Consolidate AHK Scripts' Tray Icons)

24 Jan 2024, 00:00

@Jasonosaj
Even if you can add menus to mainscript
How do you make other scripts execute mainscript menu commands

Then you may have to modify all the sub scripts.
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: AHK Startup (Consolidate AHK Scripts' Tray Icons)

24 Jan 2024, 14:17

viv wrote:
24 Jan 2024, 00:00
@Jasonosaj
Even if you can add menus to mainscript
How do you make other scripts execute mainscript menu commands

Then you may have to modify all the sub scripts.

Yes, adding another scripts tray menu to AHK Startup's tray menu is next to impossible. When this script starts another script, the other script does not even have a custom menu yet. And the custom menu of the other script could be defined or changed by the other script at any time. And as stated, there is the issue of a click on this script's 'custom' menu would then have to run code in the other script. So, yes, that kind of cross script communication would require adding code to the other script.

One possibility would be to have a menu item on the AHK Startup's tray menu to add back the other script's tray icon and then call the other script's tray menu. I believe when this script deletes a tray icon the information is not truly erased, and the tray icon can be restored.

I believe this line DllCall('Shell32\Shell_NotifyIcon', 'UInt', NIM_DELETE, 'Ptr', nic) can be reversed but I have not tried it.

Maybe I will play around with it and see how hard it is to add a tray icon back. Not sure it is worth the trouble though. In general, any script where the coder created a custom tray menu, probably the custom menu is important and should probably be easily accessible with its own tray icon.

For example, I run about a dozen scripts through AHK Startup but have two scripts that still start separately because they are substantial scripts with their own tray menus and custom icon graphics.

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

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: No registered users and 30 guests