Created
November 13, 2017 12:13
-
-
Save davebrny/4b329b604ce742ba2581b6e691afea57 to your computer and use it in GitHub Desktop.
(autohotkey) - tray option to run your scripts at startup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
run_at_startup(seperator="", menu_name="tray") { | |
global ras_shortcut, ras_menu | |
ras_menu := menu_name | |
if (seperator = "1") or (seperator = "3") | |
menu, % ras_menu, add, | |
menu, % ras_menu, add, Run At Startup, run_at_startup | |
splitPath, a_scriptFullPath, , , , script_name | |
ras_shortcut := a_startup "\" script_name ".lnk" | |
ifExist, % ras_shortcut | |
{ | |
fileGetShortcut, % ras_shortcut, target ; update target if script has moved | |
if (target != a_scriptFullPath) | |
fileCreateShortcut, % a_scriptFullPath, % ras_shortcut | |
menu, % ras_menu, check, Run At Startup | |
} | |
else menu, % ras_menu, unCheck, Run At Startup | |
if (seperator = "2") or (seperator = "3") | |
menu, % ras_menu, add, | |
} | |
run_at_startup: ;# action when tray item is clicked | |
ifExist, % ras_shortcut | |
{ | |
fileDelete, % ras_shortcut | |
menu, % ras_menu, unCheck, Run At Startup | |
trayTip, , Startup Shortcut removed, 5 | |
} | |
else | |
{ | |
fileCreateShortcut, % a_scriptFullPath, % ras_shortcut | |
menu, % ras_menu, check, Run At Startup | |
trayTip, , Startup Shortcut created, 5 | |
} | |
return | |
/* | |
[script info] | |
version = 3.0 | |
description = tray option to run your scripts at startup | |
author = davebrny | |
source = https://gist.github.com/davebrny/bb958c31da5359263e1ba33cf7fe7fd5 | |
*/ |
compact version
menu, tray, add, Run At Startup, run_at_startup
menu, tray, % fileExist(a_startup "\" a_scriptName ".lnk") ? "check" : "unCheck", Run At Startup
run_at_startup: ; tray menu label
if fileExist(a_startup "\" a_scriptName ".lnk")
fileDelete, % a_startup "\" a_scriptName ".lnk"
else fileCreateShortcut, % a_scriptFullPath, % a_startup "\" a_scriptName ".lnk"
menu, tray, % fileExist(a_startup "\" a_scriptName ".lnk") ? "check" : "unCheck", Run At Startup
return
great! how to save the value after reload?
great! how to save the value after reload?
which value are you referring to?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
run at startup
usage
- add
run_at_startup.ahk
to one of the function libraries- add
run_at_startup()
to the auto-execute section of your script- click on "Run At Startup" in the tray to add or remove the script shortcut from the startup folder
options
run_at_startup(1)
1 - add a separator before
2 - add a separator after
3 - add a separator before + after
(leave empty to add none)
the "Run At Startup" item is added to the "tray" menu by default. if you want to add it to a sub-menu inside the tray then pass that menu name to the second parameter
run_at_startup(1, sub_menu_name)