Autohotkey Script Examples

EDIT: Changed Chrome to Todoist in the description of line 6. Sorry for the mix-up.

Another one from my Todoist days. I never really got into the Todoist desktop client, preferring to use it in a web browser instead. I tried keeping multiple Todoist tabs open, but it never quite worked well, so instead I devised a series of scripts that helped me switch between Todoist views with a keybinding. This one switches to a project view, but you can substitute the name of a tag, a saved search, or the inbox in line 20.

To break down the script:

  • Lines 1-3 … I’ve covered #SingleInstanceForce and SetTitleMatchMode before.
  • Line 4 … WinActivate brings the topmost (in the alt-tab stack) Chrome tab to the front.
  • Line 6 … Loop tells the script to run through this loop and stop after 15 iterations. I’m not usually one to have more than 3-4 tabs open at any one time, so 15 is more than enough for me. If there isn’t a tab with Todoist in the title, this limit prevents the script from going on forever.
  • Line 8-12 … gets the title of the Active window (the final argument A is the designator for the active window). The InStr command looks for any string that has the sub-string Todoist, and if it finds it, the loop terminates.
  • Line 13 … if the tab title does not contain Todoist then switch to the next tab and try again.
  • Line 14 … sleep pauses the script for the given number of miliseconds. This was just enough to give the browser enough time to switch the tab and register the name before testing again.
  • Lines 17-24 … once the Todoist tab is found, it uses the keyboard shortcut / to jump to the search box, type the name of the project, select it, and press return. The Send command gives keystrokes by typing rather than pasting.

A few other notes:

  • At least when I was writing these scripts regularly, Autohotkey demanded the braces be as they are here rather than OTB format. Its been a few years and they might have changed the requirement.
  • I had a series of these for my most used perspectives (aka saved searches), labels, etc.
  • You can use this for pretty much any web-based tool, so long as there is some sort of keyboard-y way to get to things.
  • I can’t remember whether Autohotkey has a way to click at an image or click at a specific screen location, but that would be a way around not having a keyboard shortcut to use.

#SingleInstance force

SetTitleMatchMode, 2
WinActivate, - Google Chrome

Loop, 15
{
   WinGetTitle, Title, A  ;get active window title
   if(InStr(Title, "Todoist")>0)
   {
      break ; Terminate the loop
   }
   Send ^{Tab}
   Sleep, 50
}

Sleep, 50
Send {/}
Sleep, 20
Send [$_PROJECT NAME]
Sleep, 20
Send {down}
Sleep, 20
Send {return}

return

2 Likes