Here’s a sampling of scripts I’ve written in Autohotkey. All are set to run under AutoHotkey 2.x.
NOTES:
1) Almost all of my scripts are triggered through Streamdeck buttons. For those I use the extended Function keys (F13 through F24). This avoids potential collisions with an application’s built-in keyboard shortcuts. I like to keep my applications’ shortcut keys unchanged so if I ever lose my configuration I don’t have to go in and redo all of my changes. I do all of my shortcuts through AutoHotkey.
For scripts not running through a Streamdeck button I use keyboard shortcuts.
2) I always put the following at the top of the file that contains my scripts:
#Requires Autohotkey v2.0+ ;says that this script can only be execud by AHK v2.x
SetTitleMatchMode 2 ; goes before +Escape because that stops autoexecute section
SendMode “Input”
#SingleInstance Force ; this eliminates the “there is an older instance …” message box popping up when running it again
TraySetIcon “D:\OneDrive\My Icons\Scrivener icon 2.jpg”
;everything above this is the Autoexecute section. This is not necessary because the +Escape would automatically end the AutoExecute section, but this makes it clear that it ends here.
; Use Shift+Esc as a Kill Switch, in case a script needs to be interrupted. This will terminate this entire script file.
+Escape::ExitApp
#HotIf WinActive(“ahk_exe scrivener.exe”) ; only activate the following scripts if Scrivener is active
Scripts using keyboard shortcuts rather than extended function keys—these are scripts i execute from the keyboard directly:
^+h:: ;this simply highlights the cursor position momentarily—use control shift a to highlight the text around to the cursor, pause, then deselect it; useful in applications where you might have trouble visually finding the cursor
{
Send “{Left}” ; move to left to include one character there, in case I’m at the end of a paragraph where it will otherwise be hard to see
Sleep 300
Send “^+{Right 2}” ; highlight whatever is to the right of the cursor
Sleep 600 ; pause for specified number of milliseconds to allow me to see where the cursor is
Send “{Left}{Right}” ; stop highlighting and return the cursor to where it was
}
^;:: ; this script sets Control + ; to open a dialog where you type the document name, then hits Enter, then Ctrl+Right. In Scrivener this creates a new document indented to the right below the current document.
{
vfilename := InputBox(“Document Name”, “Enter the name of the new document”, “w400 h125”) ; set ctrl+; to pop up input box and get name of new file
Send “^n”
Sleep 200
Send vfilename.value “{Enter}”
Sleep 200
Send “^{Right}”
}
^+;:: ; this script sets Control + Shift + ; to open a dialog where you type the document name, then hits Enter, then Ctrl+Left. In Scrivener this creates a new document outdented to the left below the current document.
{
vfilename := InputBox(“Document Name”, “Enter the name of the new document”, “w400 h125”) ; set ctrl+; to pop up input box and get name of new file
Send “^n”
Sleep 200
Send vfilename.value “{Enter}”
Sleep 200
Send “^{Left}”
;Send ^{Tab}
}
Scripts using extended function keys that are triggered through Streamdeck buttons:
The following two scripts open layouts I have saved in Scrivener. These two layouts appear at the bottom of the Layouts menu so “Up 1” and “Up 2” select them.
+#F13:: ; Scrivener use Shift+Win+F13 to open Layouts window and select Single pane binder inspector bookmarks
{ Send “!{w}”
Sleep 200
;Send “{AltUp}”
Send “{l}” ;open layouts dialog
Sleep 200
Send “{Up 2}”
Sleep 200
Send “{Enter}”
}
+!#F13:: ; Scrivener use Shift+Exclamation+Win to open Layouts window and select Double pane binder inspector bookmarks
{ Send “!{w}”
Sleep 200
Send “{l}” ;open layouts dialog
Sleep 200
Send “{Up 1}”
Sleep 200
Send “{Enter}”
}
^!F13:: ; Scrivener use Ctrl+Shift+F13 to swap editors
{
Send “{AltDown}{v}” ;open View menu
Sleep 200
Send “{AltUp}”
Send “{l}” ;open layouts dialog
Send “{w}” ;swap editors
}
!#F13:: ;Scrivener: Alt+Win+F13 to open Quick Search
{
Send “!e” ;open Edit menu
Sleep 200
Send “f” ;select Find
Sleep 200
Send “q” ;Select Quick Search
}
F18:: ; Scrivener Open the 1st bookmark in the bookmarks list (most likely Scratchpad 1) in QR window are listed near the top of the Nav / Go To menu
{
Send “!{n}” ;open Navigation menu
;Sleep 200
Send “{r}” ;Go to Open Quick Reference menu
Sleep 200
;Send “{Down 1}” ;select 1st bookmark
Send “{Enter}”
}
F13:: { ;Scrivener - use F13 to display Bookmarks in Inspector
Send “!{n}” ;open Navigation menu
Sleep 100
Send “{p}” ;select Inspect
Sleep 100
Send “{b}” ;select Bookmarks
}
^F13:: { ;Scrivener - use Ctrl + F13 to display Snapshots in Inspector
Send “!{n}” ;open Navigation menu
Sleep 100
Send “{p}” ;select Inspect
Sleep 100
Send “{p}” ;select Snapshots
}
^+!F13:: { ;Scrivener - use Ctrl+Shift+Alt+F13 to display Synopsis in Inspector
Send “!{n}” ;open Navigation menu
Sleep 100
Send “{p}” ;select Inspect
Sleep 100
Send “{s}” ;select Synopsis
}
^!#F13:: { ;Scrivener - use Ctrl+Alt+Win+F13 to display Custom Metadata in Inspector
Send “!{n}” ;open Navigation menu
Sleep 100
Send “{p}” ;select Inspect
Sleep 100
Send “{m}” ;select Custom Metadata
}
^+F13:: { ;Scrivener - use Ctrl+Shift+F13 to take a snapshot of the current document
Send “!{d}” ;open Documents menu
Sleep 100
Send “{s}” ;select Snapshots
Sleep 100
Send “{s}” ;select Take Snapshot
}
!F13:: { ;Scrivener - Alt+F13 to Reveal in Binder
Send “!n” ;Open Navigate menu
Sleep 100
Send “{Enter}”
}
!+F13:: { ;Scrivener - Toggle Search or go to Search field
Click 220, 75
}
#F13:: { ;Scrivener - Open as quick reference
Send “!n” ;open Navigate menu
Sleep 100
Send “o” ;select Open
Sleep 100
Send “q” ;select Quick Reference
}
#+F13:: { ;Scrivener - open Add to Collection menu
Send “!{d}”
Sleep 100
Send “{d}”
}
!#+F13:: ; Use Alt+Shift+F13 to send Enter then add a solid line separator
{
Send “{Enter}”
Sleep 200
Send “_______________________________”
Send “{Enter}”
}
^+F13:: ;Scrivener: use Ctrl + Shift + F13 to open the document under the cursor in the binder in a quick reference window
{
Send “!+l” ;turn on Lock in place so the current editor doesn’t change to the file selected in the binder
Click “Right” ;open right click menu for item selected in binder
Sleep 400
Send “{o}” ;select ‘Open’
Sleep 400
Send “{q}” ;select ‘Quick Reference’
Sleep 400
Send “!{Tab}” ;return to active editor before turning off Lock in Place
Sleep 400
Send “!+l” ;turn off Lock in place so the current editor again changes to the file selected in the binder
Sleep 200
Send “!{Tab}” ; bring up the Quick Reference window that just opened
}
^+F16:: { ;Scrivener - use Ctrl+Shift+F16 to take a snapshot of the current document
Send “!{d}” ;open Documents menu
Sleep 100
Send “{s}” ;select Snapshots
Sleep 100
Send “{s}” ;select Take Snapshot
}