The goal here was to create 5 sections in a customized tray icon, (About/Edit/Suspend/Restart/Quit) you can use this to either control multiple scripts with a single tray icon like it was a single program, or simply to manage your own group of personal scripts, in which case you can ignore the About section. Aside from Suspend we are gonna do it all externally because I like the idea of having an external app that can suspend, restart or quit all the scripts, it gives us more options. So were gonna create some mini-apps, some converted from batch files and some converted from AHK files. You can use the icons I made or create your own, I'll place links for everything in this thread at the bottom of the post. Use Bat to Exe Converter and the icons provided to convert your batch files, the AHK files can be converted with icons using ahk2exe which can be found in your AutoHotkey v2 installation folder. The VBS file does not need to be converted. All files go in your working directory, including AutoHotkey64.exe and AutoHotkey32.exe (v2.0.2).
About.bat
The only point of this is to add an icon to the Start Menu which provides the user with basic information on your program, so if your not interested in creating a shortcut to this then you might as well open the VBS file directly.
About.vbs
This provides the user with basic information on your program.
Edit.batCode: Download
- x=msgbox("PROGRAMVERSION" & vbNewLine & "Copyright © YEAR NAME" & vbNewLine & "HomePage: LINK" ,64, "About PROGRAMNAME")
This will open your scripts for editing.
Quit.ahk
This will close all your scripts in a manner that will allow fluent running of your exit scripts.
Restart.ahkCode: Download
- #NoTrayIcon
- DetectHiddenWindows True
- A_Command := 0x0111
- A_Quit := 65405
- PostMessage A_Command, A_Quit,,, "SCRIPTNAME.ahk ahk_class AutoHotkey"
- DetectHiddenWindows True
- A_Command := 0x0111
- A_Quit := 65405
- PostMessage A_Command, A_Quit,,, "SCRIPTNAME.ahk ahk_class AutoHotkey"
- DetectHiddenWindows True
- A_Command := 0x0111
- A_Quit := 65405
- PostMessage A_Command, A_Quit,,, "COMPILEDSCRIPTNAME.exe ahk_class AutoHotkey"
This will restart all your scripts in a manner that will allow fluent running of your exit scripts.
Launcher.bat
This will launch multiple scripts at once and wait to launch the next commands until AutoHotkey closes. After AutoHotkey closes it can kill additional software your scripts have running.
TrayApp.ahkCode: Download
- start "" /w AutoHotkey64.exe SCRIPTNAME.ahk | AutoHotkey32.exe SCRIPTNAME.ahk
- taskkill /f /im PROGRAMNAME.exe
- taskkill /f /im PROGRAMNAME.exe
- taskkill /f /im PROGRAMNAME.exe
- taskkill /f /im PROGRAMNAME.exe
- exit
And now we will create the main tray app. The script for suspending your scripts must be contained here so we can change the icon to reflect your scripts being suspended even as the tray app doesn't get suspended. For this to work, place Enabled.ico and Disabled.ico in your working directory.
Code: Download
- try SetWorkingDir "PATH"
- tray := A_TrayMenu
- A_Suspended := "0"
- A_TrayMenu.delete("&Suspend Hotkeys")
- A_TrayMenu.delete("&Pause Script")
- A_TrayMenu.delete("E&xit")
- A_TrayMenu.Add("About", A_MenuHandler1)
- Persistent
- A_MenuHandler1(ItemName, ItemPos, MyMenu) {
- try Run 'PATH\About.exe'
- }
- A_TrayMenu.Add("Edit", A_MenuHandler2)
- Persistent
- A_MenuHandler2(ItemName, ItemPos, MyMenu) {
- try Run 'PATH\Edit.exe'
- }
- A_TrayMenu.Add("Suspend", A_MenuHandler3)
- Persistent
- A_MenuHandler3(ItemName, ItemPos, MyMenu) {
- DetectHiddenWindows True
- A_Command := 0x0111
- A_Suspend := 65404
- PostMessage A_Command, A_Suspend,,, "SCRIPTNAME.ahk ahk_class AutoHotkey"
- DetectHiddenWindows True
- A_Command := 0x0111
- A_Suspend := 65404
- PostMessage A_Command, A_Suspend,,, "SCRIPTNAME.ahk ahk_class AutoHotkey"
- global A_Suspended
- if A_Suspended = "0"{
- A_Suspended := "1"
- try TraySetIcon "Disabled.ico"
- }else{
- A_Suspended := "0"
- try TraySetIcon "Enabled.ico"
- }
- }
- A_TrayMenu.Add("Restart", A_MenuHandler4)
- Persistent
- A_MenuHandler4(ItemName, ItemPos, MyMenu) {
- try Run 'PATH\Restart.exe'
- }
- A_TrayMenu.Add("Quit", A_MenuHandler5)
- Persistent
- A_MenuHandler5(ItemName, ItemPos, MyMenu) {
- try Run 'PATH\Quit.exe'
- }
- try Run 'PATH\Launcher.exe'
Finally, once your scripts are completed and fully tested, add this line to your scripts to hide their tray icons.
Code: Select all
#NoTrayIcon
Download Bat to Exe Converter: https://www.mediafire.com/file/5muq1k44nipshgy/Bat_to_Exe_Converter.exe
Download Icons: https://app.mediafire.com/uaw07bo8uh409
Download Icons (Zipped): https://www.mediafire.com/file/zvvakm5tmxms5jn/Icons.zip
[Mod action: Moved topic from “AutoHotkey v2 Scripts and Functions”]