Skip to content

Instantly share code, notes, and snippets.

@db93n2
Last active November 13, 2017 12:22
Show Gist options
  • Save db93n2/bb958c31da5359263e1ba33cf7fe7fd5 to your computer and use it in GitHub Desktop.
Save db93n2/bb958c31da5359263e1ba33cf7fe7fd5 to your computer and use it in GitHub Desktop.
🚩 (autohotkey) - tray option to start your scripts when windows starts
start_with_windows(seperator="", menu_name="tray") {
global sww_shortcut, sww_menu
sww_menu := menu_name
if (seperator = "1") or (seperator = "3")
menu, % sww_menu, add,
menu, % sww_menu, add, Start with Windows, start_with_windows
splitPath, a_scriptFullPath, , , , script_name
sww_shortcut := a_startup "\" script_name ".lnk"
ifExist, % sww_shortcut
{
fileGetShortcut, % sww_shortcut, target ;# update if script has moved
if (target != a_scriptFullPath)
fileCreateShortcut, % a_scriptFullPath, % sww_shortcut
menu, % sww_menu, check, Start with Windows
}
else menu, % sww_menu, unCheck, Start with Windows
if (seperator = "2") or (seperator = "3")
menu, % sww_menu, add,
}
start_with_windows: ;# action when tray item is clicked
ifExist, % sww_shortcut
{
fileDelete, % sww_shortcut
menu, % sww_menu, unCheck, Start with Windows
trayTip, , Startup Shortcut removed, 5
}
else
{
fileCreateShortcut, % a_scriptFullPath, % sww_shortcut
menu, % sww_menu, check, Start with Windows
trayTip, , Startup Shortcut created, 5
}
return
/*
[script info]
version = 2.1
description = tray option to start your scripts when windows starts
author = davebrny
source = https://gist.github.com/davebrny/bb958c31da5359263e1ba33cf7fe7fd5
*/
@db93n2
Copy link
Author

db93n2 commented Feb 12, 2017

start with windows

Β 

new version/name here: run_at_startup() https://gist.github.com/davebrny/4b329b604ce742ba2581b6e691afea57

Β 

usage

- add start_with_windows.ahk to one of the function libraries
- add start_with_windows() to the auto-execute section of your script
- click on "Start With Windows" in the tray to add or remove the script shortcut from the startup folder

Β 

options

start_with_windows(1)

1 - add a separator before
2 - add a separator after
3 - add a separator before + after
(leave empty to add none)

the "Start With Windows" 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

start_with_windows(1, sub_menu_name)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment