# Autohotkey Script Examples

Back in my Windows days, I used Todoist as my task manager. Todoist has many great qualities, but when I was brainstorming and project planning, I wanted the flexibility that a text editor could give me. I made this script to transform a taskpaper-type syntax into a file that Todoist could use (it used to be that you could import from a text file using a specific syntax. I don’t know if that’s possible anymore.)

Breaking down the script:

• Lines 3-5 … I’ve covered #singleinstance force and SetTitleMatchMode before. I use them in nearly every script.
• Line 7 … WinActivate activates the window with “Notepad++” somewhere in the title.
• Line 8 … pauses the script until Notepad++ is the foreground window. Since I’m sending generic copy/paste commands, I wanted to make sure I’m doing those on the right window.
• Lines 10-12 … select and copy all.
• Line 14 … take the contents of the clipboard and assign it to the variable SL_Input.
• Line 15 … create a variable with the current timestamp, down to the second.
• Line 17 … In taskpaper, a project is defined by a colon at the end of the line. I use this variable to test whether the line is a project or not.
• Lines 19-26 … The heart of the script depends on a series of text replacements. Here I define the text elements the script looks for.
• Lines 28-34 … these are the text elements that get substituted for their related ones above. They’re built on the syntax that Todoist used to use for template import.
• Line 37 … replaces all carriage returns with that star-like character. The text parser in line 48 depends on a single character, and it could not recognize a line break. So I replace all line breaks (rn) with this character.
• Line 38-45 … replace the text elements, changing the bulleted list into the ellipsis-delineated list. They’re done in reverse order because of the way the text replacement function works: a bullet with 8 spaces could be recognized as a bullet with 4 spaces and 4 empty spaces in front of it. I never figured out how to make the tolerance tighter without totally ruining the script.
• Line 48 … this loop is how I write the new file in the proper format. the parse command tells the loop to cycle through the text in sl_input, breaking at every instance of the star character.
• Line 50 … the StringRight command takes the first character from the right hand side of the string and puts it in the variable Project_Test. This tests whether the line defines a project. Note that if there’s a space at the end of the line, it will take that and miss a project definition.
• Line 53 … if the line defines a project, it gets appended to the file with Markdown bold syntax. Its my preference to have project titles bolded, and Todoist parses some Markdown, so I used it. I explained the FileAppend command in the script above
• Line 57 … if the line is not a project, it gets appended to the file as is.
• Line 59 … adds a return between lines.

A few other notes:

• I would sometimes save multiple files during the course of a day and then import them all at once. By having the filename be the timestamp down to the second, I could be confident that I would overwrite one file with another. I could have done it down to the minute, but then what fun would that be?
• I have another similar script that lets me clean up Kindle notes. Use case: go to the Kindle notes page on the web, copy and paste notes into a text editor, run the script to remove all the excess formatting .
• I have another one that cleans up an email list for meeting notes. Use case was to hit reply-all to a meeting invite and copy the single line of multiple email addresses. The script would then turn that into a bulleted list with one name per line and put it on the clipboard. I could then paste a nicely formatted list of everyone on the invite into my notes. Yes, OneNote and the clipper will do that also, but where’s the fun in that?
• I had a pair that would remove star bullets and replace them with dashes. You know, because I’m civilized.
• I had another pair that would remove bullets and replace bullets. Used this a lot less than I thought I would.
; Turn bulleted list into todoist

#SingleInstance force

settitlematchmode, 2

Send ^a
sleep 10
Send ^c

SL_input = %clipboard%
FormatTime, TimeString,,yyyy-MM-dd_HH-mm-ss

Project_Char := ":"

SL_LCom1 := "//"
SL_LCom2 :="--"
SL_L0 := ""
SL_L1 := "- "
SL_L2 := "    - "
SL_L3 := "        - "
SL_L4 := "            - "
SL_L5 := "                - "

SL_RCom :="[[NOTE]]: "
SL_R0 :=
SL_R1 := "..."
SL_R2 := "......"
SL_R3 := "........."
SL_R4 := "............"
SL_R5 := "..............."

StringReplace, sl_input, sl_input, rn , ¤, All
StringReplace, SL_input, SL_input, %SL_LCom1%, %SL_RCom%, All
StringReplace, SL_input, SL_input, %SL_LCom2%, %SL_RCom%, All
StringReplace, SL_input, SL_input, %SL_L5%, %SL_R5%, All
StringReplace, SL_input, SL_input, %SL_L4%, %SL_R4%, All
StringReplace, SL_input, SL_input, %SL_L3%, %SL_R3%, All
StringReplace, SL_input, SL_input, %SL_L2%, %SL_R2%, All
StringReplace, SL_input, SL_input, %SL_L1%, %SL_R1%, All
StringReplace, SL_input, SL_input, %SL_L0%, %SL_R0%, All

Loop, parse, SL_input, ¤,
{
StringRight, Project_Test, A_Loopfield, 1
If Project_Test = %Project_Char%
{
FileAppend, **%A_Loopfield%**, C:\[PATH]\%TimeString%.txt
}
else
{
FileAppend, %A_Loopfield%, C:\[PATH]\%TimeString%.txt
}
FileAppend, r, C:\[PATH]\%TimeString%.txt
}

ExitApp



This next one is fun because it was inspired by @David’s “Thank You / You’re Welcome” TextExpander group. I wrote this before TextExpander on Windows was a thing. It would have been a lot easier to write the script as a series of simple text replacements, but I used it as an excuse to learn about arrays and loops, because, you know, geek.

To break down the script …

• Lines 5-8 … zero-ing out a few variables
• Line 10 … instantiates the array named TYYWArray
• Lines 11-23 … adds the array elements. I defined this one as a 2D array with 4 rows for each column in the table. I can’t remember why I put the single letters in the first column, but it looks like I never use them in the rest of the script. After that is the name of the language, the text of “thank you”, and the text of “you’re welcome”.
• Line 25 … defines a string that gets used in the pop-up selector box in line 27. Looking at this again, it would have been more elegant to do a Loop function to define the names.
• Lines 27-29 … Defines the GUI pop-up box. Line 27 defines the overall box and assigns the output to the variable lang_choice. Note that the v is there to define it as a variable. Line 28 defines the buttons being pressed. Line 29 gives the window title.
• Line 30 … Return is much like an output command. If you give no argument for Return, it simply terminates the script. To be honest, I’m not entirely sure why it is here, but I know the script doesn’t work without it.
• Lines 32-35 … tells the script what ro do once the pop-up box is closed
Line 37 … StringSplit takes 3 arguments: the variable into which the split content goes, the variable that has the content to be split, and the delimiter used to make the splits. %A_Space% is a built-in Autohotkey variable that is a space, so in this example the script takes the contents of the variable lang_choice from the picker box in line 27, splits it at every space, and puts the output into the variable tyywss. Autohotkey will add ordinal numbers to the end of tyywss for each of the split sub-strings (tyywss1 gets everything up to the first space, tyywss2 gets everything from the first to the second spaces, etc).
Lines 39-44 … tests whether I wanted “Thank You” or “You’re welcome”. tyywss1 will always have 2 letters, either “TY” or “YW”. The nested if statements assign the column number for the array in the variable k. The last if statement is there as a check in case there was an error.
• Lines 46-52 … goes into the array and pulls out the appropriate phrase. It cycles through the array and tries to match the language selected (which is in tyywss2) to the language in the array col 2. Once it matches, it pulls out the phrase wanted. Note the convention % variable is the same as %variable, namely that it gives the content of the variable instead of the variable as a thing to manipulate.
Line 54 … SendInput gives the output by typing.

A few other notes:

• This method works well for anything that you could represent as a multi-column table from which you want to look up values. Its particularly nice because you only have to define the output items in one place, and the rest of the script is pretty much reusable.
• Some examples of other scripts I have include an emoji picker, a symbol picker, contexts for task mangement systems, email addresses, often used mailing addresses, an even for my phone numbers.
• I also have one that gives me multiple options for how to format the current date.

; Thank You / You're Welcome Picker

#SingleInstance force

j = 0
k = 0
lang_choice =
lang_options =

TYYWArray := Object()
TYYWArray.Insert(["c","Chinese","Xiexie","Bu Keqi"])
TYYWArray.Insert(["a","Farsi","Mamnunam","Khahesh mikonam"])
TYYWArray.Insert(["f","French","Merci beaucoup","De rien"])
TYYWArray.Insert(["g","German","ich danke Ihnen sehr","Bitte sehr"])
TYYWArray.Insert(["i","Italian","grazie mille","prego"])
TYYWArray.Insert(["j","Japanese","domo arigato gozaimasu","do itashimashitev"])
TYYWArray.Insert(["k","Korean","kamsahamnida","anieyo"])
TYYWArray.Insert(["r","Russian","Spasibo bolshoe","Dobro pozhalovat"])
TYYWArray.Insert(["t","Turkish","Tesekkur ederim","Bir sey degil"])
TYYWArray.Insert(["y","Yiddish","A sheynem dank","Nishto farvos"])

Lang_options = TY Chinese|TY Farsi|TY French|TY German|TY Hindi|TY Italian|TY Japanese|TY Korean|TY Portuguese|TY Russian|TY Spanish|TY Turkish|TY Yiddish|YW Chinese|YW Farsi|YW French|YW German|YW Hindi|YW Italian|YW Japanese|YW Korean|YW Portuguese|YW Russian|YW Spanish|YW Turkish|YW Yiddish|

Gui, Add, ListBox, vlang_choice h100, %lang_options%
Gui, Show, Center, Thank You / You're Welcome Picker ; The window's title
return

GuiClose:
ButtonOK:
Gui, Submit ; Save the input from the user selection
Gui, destroy

StringSplit, tyywss, lang_choice, %A_Space%

if tyywss1 = TY
k = 3
else if tyywss1 = YW
k = 4
else
k = 2

for j in TYYWArray
{
if tyywss2 = % TYYWArray[j,2]
{
output_greeting = % TYYWArray[j,k]
}
}

Sendinput %output_greeting%

ExitApp



Another quick one to post. This one gives a bunch of different formatting options for the current date. It, too, uses a pop-up box to select the date format.

To break down the script …

• Lines 5-10 … defines the different formats for the current date and time. The formats follow the typical UNIX conventions. LongDate is Friday, August 3, 2018.
• Line 12 … defines a variable that is used to populate the choices in the pop-up box. Note that I wrapped each variable in % so the picker box displays the actual date and time rather than the names of the variables.
• Lines 14-22 … defines the picker box and what happens when the buttons are pressed. Same code block as in the previous script.
• Line 24 … sends the selected format by typing.

A few other notes

• This is a handy method if you want to make a selection picker box without too much work.
• You could put a list of links to launch, or apps to launch (setting the target to the full path of the app and using the run command, or even iTunes Playlists (copy the link to the playlist from the ellipsis menu, set that as the target of the choice, and use the run command. The first time you do it your default browser will ask whether you want to run iTunes. If you say “yes” it will open up the playlist in iTunes from then on).

; Time/Date Stamp Picker

#SingleInstance force

FormatTime, bdatetime,,yyyy-MM-dd
ForMatTime, ddatetime,,LongDate
FormatTime, fdatetime,,yyyy-MM-dd_HH-mm-ss
FormatTime, ttimetime,,HH:mm, dddd MMMM d, yyyy
FormatTime, gdatetime,,yyyy-MM-dd HH:mm
FormatTime, ctimetime,, HH:mm

Time_Options = %ddatetime%|%ttimetime%|%fdatetime%|%gdatetime%|%bdatetime%|%ctimetime%

Gui, Add, ListBox, vtime_choice h100 w200, %time_options%
Gui, Show, Center, Time and Date Picker ; The window's title
return

GuiClose:
ButtonOK:
Gui, Submit ; Save the input from the user selection
Gui, destroy

SendInput %time_choice%

ExitApp


1 Like

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

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

A couple of odds and ends that don’t warrant individual posts.

Just a word on the notation. Autohotkey uses the following notations for modifier keys:

^ = control
! = alt
+ = shift
# = windows key
xxx :: xxx = the double colon signifies remapping the thing before to the thing after



I had a bunch of keybindings that launched specific programs. While I could do that with Launchy (the closest thing Windows has to Quicksilver/Alfred/Launchbar/etc), I found the keybindings a bit faster. I had these for all the Office programs, Windows Explorer, specific folders, websites. I even had one that opened a specific file that I used multiple times a day.

#+e:: run C:\{PATH TO OFFICE DIRECTORY}\EXCEL.EXE

Autohotkey lets you set the transparency of a window. I found I used this most when i was on the laptop screen only and wanted to refer to an excel while I was making a powerpoint. Using the pair of commands below lets you hold down control shift windows space to make the foreground window transparent and then reset to full opaque when you release the keys. The second to last argument is the % transparency (100 is fully transparent). The last argument A designates the topmost active window.

^+#Space::WinSet, Transparent, 50, A
^+#Space UP::WinSet, Transparent, OFF, A


I spent a lot of time in Excel (still do, for that matter). In Windows Excel, Control Page Up/Down lets you switch between tabs. I used these keybindings to remap those to Windows F1/F2 which was much easier to press with my left hand (rather than needing both hands).

#F1::^PgUp
#F2::^PgDn


I remapped the volume key commands as below. I can’t remember whether the number is a % or something else, but 2 was an OK increment for me.

+F12::Send {Volume_Up 2}
+F11::Send {Volume_Down 2}
+F10::send {Volume_mute}


In PPT, alt v d will toggle between slide sorter mode (showing all slides in the main window) and slide editing mode (showing one slide the the main window and a column of slides to the left). I sped that up by remapping it. Note that Autohotkey behaves a little weirdly here. I could have enclosed the two Send commands in braces, but I didn’t need to. The empty Return statement is sufficient to terminate this portion of the script. If you were to use ExitApp here, the entire process would terminate and unload from memory.

^+a::
send !v
send d
return


Make a new folder in Windows Explorer. Note that Windows Explorer needs to already be the topmost active window. AppsKey simulates a right click (some keyboards have a physical key on the lower right side).

#+y::
send {AppsKey}
send w
send {enter}
return


Finally, a series of date snippets. They use what i think is the UNIX standard date formatting conventions. Each has the format in a comment on the right side of the first line. The ones that start with a number as either in the future or the last, the math for which you can see in the third line of each script. As before, the empty Return function is enough to terminate the code without exiting the entire process out of memory.

::ttime:: ; 12:25, Friday November 11, 2016
FormatTime, TimeString,,HH:mm, dddd MMMM d, yyyy
send %timestring%
return

::bdate:: ; 2016-11-11
FormatTime, TimeString,,yyyy-MM-dd
send %timestring%
return

::1bdate::
Tomorrowdate =
Tomorrowdate += 1, Days
FormatTime, Tomorrowdate, % Tomorrowdate, yyyy-MM-dd
SendInput %TomorrowDate%
return

::m1bdate::
Tomorrowdate =
Tomorrowdate += -1, Days
FormatTime, Tomorrowdate, % Tomorrowdate, yyyy-MM-dd
SendInput %TomorrowDate%
return

::ddate:: ; Friday, November 11, 2016
ForMatTime, TimeString,,LongDate
send %TimeString%
return

1 Like

In Windows Outlook, you’re able to define macros called “Quick Steps”. These let you chain together commands like “Mark as read and file in a folder”, “mark as read and create a task”, “set a follow up flag and set a category”, etc. The macros could get quite complicated, but the nice thing was that you could assign keyboard shortcuts to them and trust that they would fire off the same way every time.

For quite some time I’ve used a variation of Gina Trapani’s Trusted Trio folder for email processing. I have folders for Archive, @Action, @Waiting, and @Approvals. For each of these folders, I defined a Quick Step in Outlook that would mark the email as read and move it to the specified folder. Archive was mapped to control shift 9 and Approvals [1] was mapped to control shift 6. For @Action (control shift 8) and @Waiting (control shift 7) emails, I would flag the email for follow up, set a category, and file it away. This would put the email on the Outlook task list with a context. Later, when I switched to using Todoist, I would write the follow up task to a text file in the proper import format (see post above). I’d usually type those manually since I wanted to phrase the task in a certain way.

So how does this relate to Autohotkey? I used AHK to remap the extended Function Keys on my desktop keyboard [2] to the Quick Steps in Outlook. So I could be in Outlook, rest 4 fingers of my right hand on F16-F19 above the keypad, and process email really quickly. I usually rested my right thumb on the arrow keys, which let me navigate through my inbox even faster. And I could move my thumb up a little and reach the Delete key. It made email processing much faster.

Now that I’m Mac at work, I’ve used Keyboard Maestro to recreate this functionality to let me use the same keybindings on Mac Outlook [3].

The Autohotkey code is very straightforward. It assumes that Outlook is the foreground app when the keys are pressed, which I don’t think should be much of an issue for most people since the F16-F19 keys are “all the way over there.”

F16::^+6
F17::^+7
F18::^+8
F19::^+9


[1]: Approvals was a folder I used to collect all of those “click here to approve” emails (purchase orders, time off requests, etc). I’d batch them up and go through them every day or two.

[2]: I love love love the Apple Wired Extended Keyboard A1243. Do to The Unfortunate Soda Mishap of 2016, I lost my work one. If anyone has a working one they’re willing to part with, please get in touch!

[3]: Yes, Mac Outlook. No, not by choice.

A couple of scripts for window management. There are comments above each one to describe what each one does. To summarize the keybindings I used:

Shift Windows Right Arrow ... move one screen to the right
Shift Windows Left Arrow ... move one screen to the left
Shift Windows Up Arrow ... maximize the window
Shift Windows Down Arrow ... minimize the window
Shift Windows forward slash ... restore window to last non-maximized state
Control H ... minimize window (same as + # ↓, but to match the Mac convention)
Control Shift H ... hide all windows except active one (again, to match the Mac convention)


A few notes on the scripts:

• I borrowed these scripts from the AUtohotkey forums and only slightly modified them for my own use. I can’t remember where I got them or I’d give attribution.
• Each of the scripts have a WinGet statement. It finds the minimized/maximized state of the active window. Later in the script is a statement if (mm = 1) which restores the maximized state of the window after the move.
• some of the scripts end with send {ctrl up} {shift up} {win up}. Those are to make sure that the system doesn’t leave the keys pressed.
; ===== Move window one screen right
+#right::
WinGet, mm, MinMax, A
WinRestore, A
WinGetPos, X, Y,,,A
WinMove, A,, X+A_ScreenWidth, Y
if(mm = 1){
WinMaximize, A
}
send {ctrl up}{shift up}{win up}
return

; ===== Move window one screen left
+#left::
WinGet, mm, MinMax, A
WinRestore, A
WinGetPos, X, Y,,,A
WinMove, A,, X-A_ScreenWidth, Y
if(mm = 1){
WinMaximize, A
}
send {ctrl up}{shift up}{win up}
return

; ===== Maximize window
+#up::
winrestore, a
winmaximize, a
return

; ===== Minimize window
+#down::
WinGetActiveTitle, Title
WinMinimize, %Title%
return

; ===== Restore Window
+#/::
WinGetActiveTitle, Title
WinRestore, %Title%
return

; ===== Hide active window
^h::
WinGetActiveTitle, Title
WinMinimize, %Title%
return

; ===== Hide all other windows
^+h::
WinGetActiveTitle, Title
WinMinimizeAll
WinRestore, %Title%
return


The last scripts I have to share are a group that reassigned iTunes functions to the F keys on my desktop keyboard. In addition to rewind, play/pause, and forward, I added “activate iTunes” to F6.

A few notes

• the DetectHiddenWindows statement lets the script look at windows that are minimized to the system tray (which don’t always appear in the Alt-Tab list).
• I used window classes instead of window titles here so I could send the controls to iTunes without having to bring the window to the front first. That way I could be working on something and skip to the next song without the screen flickering. The WinGetClass statement gets the classID of the iTunes window. ControlSend sends the command to the window with the iTunes classID.
• I added Shift-F6 to activate iTunes. If its running, it comes to the front. If its not running, it launches.
+F6::
settitlematchmode 2
DetectHiddenWindows , On
IfWinExist, iTunes
WinActivate ;
else
run C:\Program Files\iTunes\iTunes.exe
DetectHiddenWindows , Off
return

+F7::
settitlematchmode 2
DetectHiddenWindows , On
wingetclass, itunes_class, iTunes
ControlSend , ahk_parent, {left}, iTunes ahk_class iTunes
DetectHiddenWindows , Off
return

+F8::
settitlematchmode 2
DetectHiddenWindows , On
wingetclass, itunes_class, iTunes
ControlSend , ahk_parent, {space}, iTunes ahk_class iTunes
DetectHiddenWindows , Off
return

+F9::
settitlematchmode 2
DetectHiddenWindows , On
wingetclass, itunes_class, iTunes
ControlSend , ahk_parent, {right}, iTunes ahk_class iTunes
DetectHiddenWindows , Off
return


I am a fellow AHKer. I would love to chime in here with scripts, advice and answers. I’m currently mobile and not able to on my phone but I will when I get home.

My current setup is Windows 10 with 4 keyboards (primary full, two more full and one Belkin game pad). I have most of the keys bound to do some sort of automation for me. I would love to share more on this of others are interested.

Excited to listen more of the show! Great work you two!

3 Likes

I think for my first example, I’m going to post my server automation script explanation. I can get into code if anyone finds it deeply interesting. So, here’s what I have going.

At my home office, I have a Windows Server running (well, it’s Windows 10 posing as a server). This server does a lot for me. It serves as my Minecraft server host machine, it runs plex, it has a little application that takes images off my canon camera and saves them to my Google Drive uploader and a small web server VM running Windows Server 2012 that hosts a little website I made.

I needed a way to start/stop these various applications when I’m not on my own network. Enter Workflows on my iOS device, Dropbox, and AHK.

Here’s the breakdown:
Workflows

• Deletes the “communication file” from my Dropbox folder
• Presents me with a list of commands I’d like to do
• Start/Stop the minecraft server
• Start/Stop the Canon utility
• Start/Stop the web server
• Start/Stop TeamViewer
• Start/Stop Plex
• From the selection it writes the associated command to a new text file in Dropbox
• The script on the server picks up that file and reads the desired command and carries it out

It’s pretty simple, but I love it and it has saved me loads of headaches! I’m particularly fond of “text file communication”. So, it’s what I lean towards when I want to transfer automation between devices.

I’ll post more on my multi-keyboard setup soon!

Cheers!

2 Likes

Here a a few of my “staples” that are always with me (in AHK script code)

These are what AHK call “Hotstrings” (think of text expander)
The setup is – :*:when_i_type_this::ItIsReplacedWithThis
Example: :*:btw::By the way – So, typing btw would instantly be replaced with By the way

:*:@work::myworkemail@mywork.com
:*:@home::fischgeek@gmail.com
:*:#work::701.xxx.xxxx
:*:#cell::701.xxx.xxxx
:*:qq::quick question for you


Some html/jquery maniuplation
This one is necessary because I never remember the proper syntax for a quick setTimeout function in javascript.

:*:jstimeout::setTimeout(function(){{} alert("Hello"); {}}, 3000);


Type in jstimeout and it spits out the below:

setTimeout(function(){ alert("Hello"); }, 3000);


Yup. I’m lazy.

:*:nbsp::&nbsp;
:*?:br/::<br />


These two just type out different console.log lines (with and without quotes in it) and sends the cursor in between the parentheses.

:*:c.l1::console.log();{left 2}
:*:c.l2::console.log('');{left 3}


Similar to the above two, these also add whatever is in your clipboard at the time so you can inspect the variable in the console.

:*:c.l3::
SendInput console.log('%Clipboard% : ' {+} %Clipboard%);
return

:*:c.l4::
SendInput console.log('%Clipboard% : ' {+} Object.keys(%Clipboard%));
return


Just a few to test the waters and see if anyone likes these. Let me know if you would like to explain more and/or post more. I have plenty!

Thanks everyone!

1 Like

For creating a new folder, you can just use the CTRL+SHIFT+N shortcut that works natively in Windows Explorer (Since Windows 7 I believe). If you wanted to keep your existing mapping you could use:

#+y::^+n

Open Windows PowerShell from Windows Explorer
This script creates a key binding (I use Windows + T) that opens Windows PowerShell in the directory you’re currently viewing in Windows Explorer by sending the key combination Alt + F to open the File menu and then sending R to open Windows PowerShell.

#t::
Send !f
Send r
return


If you prefer opening PowerShell as administrator then just send A instead of R:

#t::
Send !f
Send a
return


Edit1: Forgot to mention that I only tested this on Windows 10.
Edit2: Removed { and } as fischgeek suggested.

Why not just Run, powershell.exe

Edit2: the “{” and “}” aren’t needed in your example

Here’s one that creates a new text file if you’re in Windows Explorer and your cursor is positioned inside a directory. I found it on another forum:

#n::
Click, Right, 1
Sleep, 10
SendRaw, wt
return


It right clicks (that’s why your cursor should be positioned inside a directory in Windows Explorer) and then sends the keys w and t to the context menu to create a new text file.

Good one! Though, I’m personally not a fan of overwriting global hotkeys #n is a new Quick Note in OneNote. And, the w and t keys only works if you don’t have more things in your context menu that have the w as the trigger key. For me, I have WinZip installed and it’s trigger is a w leaving new text file the second w.

Here’s a way around that. This will copy the current path of the current File Explorer and create a new empty text file in that same directory (also notice I used !n as to not overwrite built in hotkeys).

!n::
KeyWait, n
Send, ^l^c
FileAppend,, %clipboard%\new_file.txt
return


Expanding on that, I like to keep a directory of text file notes. This one will take what you have in your clipboard, write it to a text file in your notes directory of choice then, show you the file.

^!n::
FormatTime, t,, yyyy-MM-dd-HH-mm
file = C:\path\to\notes\directory\%t%.txt
FileAppend, %clipboard%, %file%
run, %file%
return


Furthermore, if we want to use OneNote’s built in Quick Note, I made a hotkey that creates the Quick Note and adds the current date as the title triggered.

~#n::
WinWaitActive, Untitled page - OneNote
Send, ^+t
FormatTime, stamp,, yyyy-MM-dd h:mm:ss tt
SendInput, %stamp%{enter}
return


Note: the tilde in this hotkey allows the hotkey’s native function to still execute thus not overwriting it.

Hope someone gets some use out of these!

2 Likes

I use Windows at work, the Mac at home. As such, I get so little time on the Mac to learn its basics. MPU and Automators have been a big help.

If you haven’t tried it yet, AuotIt 3 is s programming language/ framework that wraps much of the windows API. You can automate s lot of GUI activity, but you have to write the code yourself.
It’s an amazing free tool though.

Good tip! The founder of AutoHotkey actually used AutoIt v2 as a base and expanded on it. In my personal opinion and preference, AHK has a lot more functionality and is easier to use/write. But, again, just my opinion. I have tried both and settled on AHK due to those reasons. It just seemed a bit more powerful too.

I encourage everyone to check them both out though! You might find that AutoIt vs AutoHotkey is a lot like Windows vs MacOS or any other opposing arguments (Google vs. MS or Android vs iOS). It just comes down to personal preference!

Cheers.

2 Likes

You’re right. I do remember reading that a few years ago, but forgot. I’ll need to look into AHK again.

Made a quick water downed version of a hotstring creator I once had. It allows you to create auto replacements on the fly.

Script code
^+h::
{
Gui, Color, White
Gui, Font, s11
Gui, Add, Edit, vtxtReplace w400 r5
Gui, Add, Edit, vtxtWith w400 r5
Gui, Add, Button, vbtnSubmit gSubmit, Submit
Gui, Show, AutoSize Center, AutoType
return
}

Submit:
{
Gui, Submit
replacementText := prep(txtWith)
newhs := ":*:" txtReplace "::" replacementText
FileAppend, n%newhs%, %A_ScriptFullPath%
ExitApp
}

GuiClose:
ExitApp

prep(str) {
str := RegExReplace(str, "\{", "{{}")
str := RegExReplace(str, "\}", "{}}")
str := RegExReplace(str, "!", "{!}")
str := RegExReplace(str, "#", "{#}")
str := RegExReplace(str, "\^", "{^}")
str := RegExReplace(str, "\+", "{+}")
str := RegExReplace(str, "\n", "n")
str := RegExReplace(str, "\r", "r")
return str
}
:*:btw::by the way
:*:qq::quick question for you