Please share your AutoHotKey macros for Scrivener

Qu
QuantumGood
Posts: 18
Joined: Mon Jun 18, 2012 11:38 pm
Platform: Windows
Contact:

Tue Jun 19, 2012 7:19 pm Post

AutoHotKey: DownloadTutorialFAQReferenceSample Scripts

Please share any AutoHotKey (or PhraseExpress) scripts you are using in Scrivener.

SCRIVENER KEYBOARD SHORTCUT TIPS:
Customize Scrivener's keyboard shortcuts via Tools>Options>Keyboard and use the "Edit Shortcut" line at the bottom of the window that pops up.
View, browse or print all keyboard shortcuts for Windows
Some regular shortcuts not working properly? Try deleting the [HKEY_CURRENT_USER]Software/Scrivener/Scrivener/Options/Shortcut key folder in Windows with the software closed and re-open. HT AmberV via this post

AUTOHOTKEY SCRIPTS:
TIP: Turn off Windows "Sticky Keys" before using AutoHotKey
Open PDF at specific page in external viewer
Split a document and retain metadata, because for now, Scrivener's built-in split function does not carrly the metadata to the newly split document.
Convert to uppercase or lowercase, by StefanG (I've PM'd StefanG for script details)

Hat Tip to narrsd and almansur for the idea of using Scrivener's built-in duplicate function, and to AmberV for patiently and wisely contributing so much to my understanding of Scrivener
Last edited by QuantumGood on Tue Jun 19, 2012 10:42 pm, edited 12 times in total.

Qu
QuantumGood
Posts: 18
Joined: Mon Jun 18, 2012 11:38 pm
Platform: Windows
Contact:

Tue Jun 19, 2012 7:23 pm Post

This is from Uku's post here:

^!F5::
clipboard =
Send, ^c
ClipWait, 2
If ErrorLevel
{
MsgBox, Page number copy to clipboard failed
Return
}
FileDelete, c:\tempcmd.txt
FileAppend, c:\pdfxcview.exe /A "page=, c:\tempcmd.txt
FileAppend, %Clipboard%, c:\tempcmd.txt
FileAppend, " "C:\Dropbox\source.pdf", c:\tempcmd.txt
FileRead, pdfcommand, c:\tempcmd.txt
Run %pdfcommand%
Return

Now I put the corresponding PDF page numbers into the Scrivener text wherever appropriate, and when I want to call the PDF, I mark the page number and then press Ctrl-Alt-F5: PDF is opened in PDF X-ChangeViewer at the correct page. I can also annotate and highlight the source PDF, as it stays in the Dropbox folder.

Qu
QuantumGood
Posts: 18
Joined: Mon Jun 18, 2012 11:38 pm
Platform: Windows
Contact:

Tue Jun 19, 2012 7:24 pm Post

In order to split and retain metadata, I have mapped the Windows-z (hold down Windows key, press z) to split a document and retain the metadata using this AutoHotKey script, which only works when the AutoHotKey script is running and the Scrivener window is active:
---------------------------------------------
SPLIT, ADD ".1" TO TITLE
---------------------------------------------
#IfWinActive ahk_class QWidget
#z::
SendInput ^+{End}^x^+d{End}.1{Enter}^{Tab}^a^v
return

---------------------------------------------
SPLIT, MAKE SELECTED TEXT TITLE
---------------------------------------------
This requires you to select text in the created split document, which I'll call the "child" document. After splitting, select the text and then use this script, which I have mapped to Windows-a (hold down Windows key, press a):

#IfWinActive ahk_class QWidget
#a::
SendInput ^c^{Tab}{F2}^v{Enter}^{Tab}{Right}{Left}
return

NOTE: If you change the initial ^c to ^x it will cut the text from the document before placing it as the title. In that case, remove the {Right}{Left} from the end, as they are superfluous.
Last edited by QuantumGood on Wed Jun 20, 2012 2:11 am, edited 2 times in total.

Qu
QuantumGood
Posts: 18
Joined: Mon Jun 18, 2012 11:38 pm
Platform: Windows
Contact:

Tue Jun 19, 2012 7:33 pm Post

Before beginning to use AutoHotKey, I suggest turning off "Sticky Keys" to avoid problems In Windows 7 (similar to Windows Vista).

Start from:
Control Panel\All Control Panel Items\Ease of Access Center\Make the keyboard easier to use
and under "Make it easier to type" uncheck box for "Turn on Sticky Keys..."
Then click link for "Set up Sticky Keys" and uncheck box for "Turn on Sticky Keys when SHIFT is pressed five times."

User avatar
AmberV
Posts: 22511
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Santiago de Compostela, Galiza
Contact:

Tue Jun 19, 2012 8:30 pm Post

These are fantastic, thanks for these! Do you mind if I move this over to the Tips and Tricks forum?
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

Qu
QuantumGood
Posts: 18
Joined: Mon Jun 18, 2012 11:38 pm
Platform: Windows
Contact:

Tue Jun 19, 2012 9:35 pm Post

Great idea! Apologies for my carelessness in overlooking that more appropriate forum.

User avatar
AmberV
Posts: 22511
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Santiago de Compostela, Galiza
Contact:

Tue Jun 19, 2012 9:39 pm Post

No worries! I'm going to have to check out AutoHotKey now, never played with it before.
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

Qu
QuantumGood
Posts: 18
Joined: Mon Jun 18, 2012 11:38 pm
Platform: Windows
Contact:

Tue Jun 19, 2012 10:06 pm Post

If you want to browse the keyboard shortcuts, bookmark this page.

While you can print them from there, Scrivener will export a text file with all keyboard shortcuts in it if you go to Tools>Options>Keyboard within Scrivener, and near the bottom of the window that pops up, click Export and then choose "For printing" to get a file you can print from.

You can also view them from Tools>Options>Keyboard, but it's not as easy as this page or printing them yourself.

To
TomGoodell
Posts: 88
Joined: Tue Nov 13, 2012 3:13 pm
Platform: Windows

Sat Nov 24, 2012 8:37 pm Post

Every time I open Scrivener I want my Keywords list to appear along the right edge of my monitor, stretched to almost the height of my monitor, and sorted. I wrote the following AHK script to do this; it uses Windows key + S to open Scrivener, switch to the keywords pane, open the keywords list, move it to the right edge of the screen near the top and resize it so the bottom of the keywords pane stretches to the bottom of the screen, click the Sort checkbox and sort the list. At the end it puts the cursor back in the upper left corner of the Editor window.

A few caveats: This uses screen coordinates relative to the Scrivener window, as well as absolute screen coordinates, so the values in the Click and WinMove commands may be different for different monitor sizes and resolutions, in which case you'll have to use Window Spy (included with AHK) to determine the right values for your computer.

If anyone has questions or needs help getting this going, let me know.

#S:: ; use the Windows + S key combination to open scrivener, open the Keywords dialog, and position it stretched out on the right side of the screen
{ Run Scrivener ; start Scrivener
WinWait, Scrivener ; wait for Scrivener to load
Click 1169, 1120 ; Switch to the keywords pane
Click 1322, 449 ; click on the Keyword menu
Send {Down}{Down}{Down}{Enter} ; select the 3rd item on the menu - show Project keywords
Sleep, 333 ; pause so Windows can catch up
WinMove, Keywords, , 1640, 127, 272, 1008 ; move the Keywords pane to the right side of the screen and resize it
Click 1532, 1115 ; click the Sort checkbox
Click 91, 42 ; click the sort bar at the top of the dialog
Click -1152, 76 ; put the cursor at the top left of the editor pane
return
}

To
TomGoodell
Posts: 88
Joined: Tue Nov 13, 2012 3:13 pm
Platform: Windows

Sat Nov 24, 2012 8:46 pm Post

Here's a simple script that pops up a dialog where you can type the name of a new item, then inserts that item as a child of the currently selected item in the browser. It uses the Ctrl+; key combination to trigger the script. Note that this is only useful if your cursor is at the bottom of a hierarchy in the browser. Note that if your on a folder, the Ctrl+N combo built in to Scrivener does already does this - it inserts a new child item under the folder your cursor is on. In that case, if you use this AHK script, it inserts the new item at the bottom of the lowest part of the hierarchy under that folder. This is a little hard to explain in words, but if you experiment with it you'll see how it works. It's a bit confusing because Ctrl+N functions differently in different contexts in the browser.

Let me know if you questions or need help with this.

#IfWinActive, ahk_class QWidget ; only execute if Scrivener is running
^;:: ; 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.
{InputBox, vfilename, Document Name ; set ctrl+; to pop up input box and get name of new file
Send ^n %vfilename% {Enter} ^{Right}
}
Last edited by TomGoodell on Tue Jul 02, 2013 7:24 pm, edited 1 time in total.

JJ
JJSlote
Posts: 469
Joined: Tue Oct 26, 2010 5:44 pm
Platform: Windows
Location: NY, USA              Docs in Binder: 10,500+

Fri Aug 14, 2015 5:55 pm Post

This macro puts a toolbar overlay on the Scrivener window, with buttons that run the alt-key combos for "Character Map" and "Reveal in Binder". You'll probably have to change the height, width and coordinates at Gui, Show. And you'll want to be running Scriv in full screen, else this overlay will float out on its own.

I've got about a 5000-line script running in conjunction with Scrivener, and it all started with something simple like this.

Rgds -- Jerome

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
FileEncoding, UTF-8
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
;
SetTitleMatchMode, 2 ; any match
WinGet ScrivName,ID,- Scrivener
;
Gui Scrivo:Default
Gui  -SysMenu -Caption
Gui  font, s8 bold, Verdana
Gui, Add, Button,x20 gCharMap, CharMap
Gui, Add, Button,ys gQReveal, Reveal in Binder
Gui +Owner%ScrivName%
Gui Color, e5e5e5, aaccaa
Gui, Show, h39 w300 x547 y46
Return
;
CharMap:
WinActivate, - Scrivener
Send !e
Send e
return
;
QReveal:
WinActivate, - Scrivener
Send !v
Send r
return



Rgds -- Jerome

To
TomGoodell
Posts: 88
Joined: Tue Nov 13, 2012 3:13 pm
Platform: Windows

Fri Aug 14, 2015 7:51 pm Post

Jerome - this is great! Thanks for posting, it will save me considerable time.

Tom