AHK Palette for Windows Scrivener

Inspired by @fto’s post, which provides a Keyboard Maestro palette to assist with simple actions in Scrivener, here is an equivalent AutoHotKey (AHK) palette I developed for myself a while ago.

The palette invokes AHK code to automate menu shortcuts that I use all the time. If you have even a minimal coding background, it should be simple to tweak the script to add and remove whatever shortcuts you like.

Pressing F10 launches the palette, which looks likes this:

image

The code is below.

AHK Palette.ahk

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

;--------------------------------------------------------------------------

SetTitleMatchMode, 2

#IfWinActive ahk_class Qt643QWindowIcon

;--------------------------------------------------------------------------

;	F10 engages the command palette
f10::

RunWait, AHK Palette_proc.ahk
return

AHK Palette_proc.ahk

;--------------------------------------------------------------------------
; Auto-Execute section
;--------------------------------------------------------------------------

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

;--------------------------------------------------------------------------

; Build command palette

Menu, Palette, Add
Menu, Palette, deleteAll

Menu, Palette, Add, &Add to Collection, AddToColl
Menu, Palette, Add, &Bullets, Bullets
Menu, Palette, Add, &Color, Color
Menu, Palette, Add, Complete Doc &Title, Title
Menu, Palette, Add, C&opyHolder, CopyHolder
Menu, Palette, Add, &Highlight, Highlight
Menu, Palette, Add, &New from Template, NewFromTemplate
Menu, Palette, Add, Outliner Selection A&ffects, Affects
Menu, Palette, Add, &Para Spacing, ParaSpacing
Menu, Palette, Add, &QuickRef, QuickRef
Menu, Palette, Add, Re&veal in Binder, Reveal
Menu, Palette, Add, &Revision Mode, Revision
Menu, Palette, Add, &Swap Editors, Swap

; Show command palette

Menu, Palette, Show
ExitApp
return

;--------------------------------------------------------------------------
; Process platette selection
;--------------------------------------------------------------------------

Affects:
Send !n
Send {Down 12}
Send {Enter}
return
;

AddToColl:
Send !d
Send d
return
;

Bullets:
Send !r
Send l
Send {Down 4}
Send {Enter}
return
;

Color:
Send {AppsKey}
Send c
Send c
return
;

CopyHolder:
Send !n
Send o
Send c
return
;

Highlight:
Send {AppsKey}
Send h
return
;

NewFromTemplate:
Send !p
Send w
return
;

ParaSpacing:
Send !r
Send p
Send l
Send {Enter}
WinWait, Line Spacing, , 10
WinActivate, Line Spacing
Send {Enter}
return
;

QuickRef:
Send !n
Send o
Send q
return
;

Reveal:
Send !n
Send {Enter}
return
;

Revision:
Send !r
Send r
Send f
return
;

Swap:
Send !v
Send l
Send w
return
;

Title:
Send !+=
KeyWait, Tab, D, T10
if ErrorLevel   ; i.e. it's not blank or zero.
		; MsgBox, error level
		return
	else
		; MsgBox, no error level
		Send ]]
return
;

Notes

  • Create and store AHK Palette.ahk and AHK Palette_proc.ahk in the same folder.
  • Copy a shortcut to AHK Palette.ahk into your Windows Startup folder.
  • The script only works when Scrivener is running.
  • For ‘Complete Doc Title’ to work, enable setting File > Options > Corrections > Corrections > Automatically detect [[document links]].

Let me know if you have any questions.

Best,
Jim

7 Likes