Sunday 25 July 2021

Working more efficiently with AutoHotkey (part 2)

AutoHotkey is a must-have tool that anyone (with a Windows computer) can use to improve their Windows experience. If you’re tired of constantly navigating menus or using multiple strokes to perform repetitive tasks and would like to simplify your work life, then AutoHotkey and the scripts below will be for you!

AutoHotkey has much more power than most people will ever use, but also offers very simple scripts. Its simplest scripts – typically just one line of code – could even turn out to be those that you'll find most useful in your day-to-day computing! 

 

A few examples: whenever I type tn, the AutoHotkey script will automatically enter the word translation. Or when I enter @@k, the script will automatically enter my email address. I remember that, before I started using AutoHotkey, it would always be a pain to constantly have to type the whole email address! Check out my earlier blog post about AutoHotkey to find out more about this.

 


Teaming up with an AutoHotkey accountability partner 

A couple of months ago I teamed up with Isabel Hurtado de Mendoza, an English-to-Spanish translator. We both had only scratched the surface of what is possible with AutoHotkey then and were keen to find out more about it. So we became accountability partners: we now report back (more or less) regularly to each other on our latest AutoHotkey discoveries and learning progress. 

Isabel and I identified AutoHotkey scripts that are particularly useful to translators as well as other computer users. We either adopted existing AutoHotkey scripts (many of which are readily available on the web) or modified and adapted them to our own purposes. You’re very welcome to adopt the scripts below as well!


Simpler AutoHotkey script editing with SciTE4AutoHotkey

I would previously edit my AutoHotkey scripts in Notepad, but recently switched to SciTE4AutoHotkey upon Isabel’s recommendation. SciTE4AutoHotkey is an AutoHotkey script editor, which provides helpful features such as syntax highlighting (to highlight any errors in AutoHotkey syntax), AutoComplete, interactive debugging and others. This might all sound very complicated, but it really isn’t!

 


Advanced AutoHotkey scripts for translators
 

The following AutoHotkey scripts are slightly more advanced AutoHotkey scripts. You’ll find a number of useful, simpler scripts in my earlier blog post about AutoHotkey.
 

Note that any text following a semicolon (;) below serves as a comment, reminding you of what the script means or what you need to do to trigger it. It won’t be executed by the AutoHotkey programme.


Launching programmes by pressing a combination of keys 

It is possible to launch any programme instantly by using a hotkey. For instance, you could set up AutoHotkey to launch Outlook and define, for example, WIN + o for this. In other words, when you press WIN + o, this will launch Outlook.


Here are some example scripts which could be used:
 

;>>>>>>>>>>>>>
; Programme ausführen/Run programmes
;>>>>>>>>>>>>>

; press WIN + o
#o::
Run Outlook.exe
return

; press WIN + f
#f::
Run firefox.exe
return

; press WIN + m
#m::
Run MicrosoftEdge.exe
return

; press WIN + c
#c::
Run calc.exe
return

Note: in AutoHotkey # designates the Windows key on your keyboard.


Creating a new file in Word or Excel

In the past, I always had to perform several clicks to create a new Word or Excel file. Now, I can create one instantly by simply pressing CTRL (or, to be more precise, Strg on my QWERTZ keyboard) + n to create a Word file and CTRL + SHIFT + % to create an Excel file, respectively.


Here are the scripts:

;>>>>>>>>>>>>>
; Neue Word-Datei/New Word file
;>>>>>>>>>>>>>

; press CTRL + n
^n::
Word := ComObjCreate("Word.Application")    
Word.Visible := True                        
Word.Documents.Add                          
Return

;>>>>>>>>>>>>>
; Neue Excel-Datei/New Excel file
;>>>>>>>>>>>>>

; press CTRL + SHIFT + %
^%::
Xl := ComObjCreate("Excel.Application")     
Xl.Visible := True                             
Xl.Workbooks.Add                             
Return   

Note: in AutoHotkey ^ designates the CTRL key on your keyboard.




Entering the £ symbol

I do a lot of business with UK companies, so I use the £ currency symbol all the time; however, since I use a QWERTZ keyboard, I don’t have a £ key on it. Thanks to AutoHotkey, though, I can enter it quickly by pressing CTRL + WIN + p.


Here is the script for it:

; create the £ sign by pressing CTRL + WIN + p
^#P::SendInput {U+00A3}  

Note: in AutoHotkey # designates the Windows key on your keyboard.

 



Creating message templates

AutoHotkey can be utilized to create message templates for use not just in an email client, but anywhere in your Windows environment, for example when writing messages in a web-based interface.


Here’s an example script for it:

;>>>>>>>>>>>>>
; E-Mail-Vorlagen/Email templates
;>>>>>>>>>>>>>

; type jobno
::jobno::Dear XX,{ENTER}{ENTER}Thank you for your new enquiry.{ENTER}{ENTER}I am sorry I'm unable to take on the project as I’m currently fully booked.{ENTER}{ENTER}Kind regards,{ENTER}{ENTER}Elisabeth




Taking a screenshot

This is a script for effortlessly taking a screenshot using Paint, combining several steps. To take a screenshot, I simply have to press CTRL+ALT+1, and all that’s left for me to do is to save the Paint file (with the screenshot in it) on my hard drive (or another storage medium).


Here is the script for it:

;>>>>>>>>>>>>>
; Screenshot erzeugen und in Paint kopieren/Take screenshot and copy it to Paint
;>>>>>>>>>>>>>

; CTRL+ALT+1
^!1::                       
sleep, 100
send {PrintScreen}
sleep, 500
Run, C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Paint
Sleep, 1000
Send, #{Up}
Sleep, 500
Mouseclick, left, 250, 250, 5
Sleep, 200
send ^v
sleep, 500

Note: Isabel and I figured out that sometimes it’s necessary to write the whole file path in the script (such as C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Paint in the script above), rather than just write “Run Paint”!


Converting a short dash to an m dash


Entering an m dash should be easy, but for some reason it often isn’t! Using an AutoHotkey script can help make sure the m dash always is there when you need it.


I now use this script:

; press Alt Gr + -
<^>!-:: Send, –                

Note that similar scripts could be used for any symbols that you use regularly, for example a script that changes square brackets to curly brackets.

 

The simplest AutoHotkey scripts – typically just one line of code – could turn out
to be those that you'll find most useful in your day-to-day computing
(image by Gerd Altmann on Pixabay)

 




Copying and pasting text into an open Word file


Collecting data while I’m researching terminology during a translation project has become way more comfortable thanks to the following script in that I no longer have to jump around between windows!

These days I only need to have a Word file open on my screen, and any text which I highlight (e.g. on a webpage or in an electronic dictionary) will then automatically be copied to this file by the script. I’ve named this file notes.docx, which is why the lines IfWinExist, notes and WinWaitActive, notes are used in this script, as shown below.



To trigger the script, I only need to press CTRL+ALT+n.



;>>>>>>>>>>>>>
; Text in Word-Datei notes.docx kopieren/Copy text to Word file notes.docx
;>>>>>>>>>>>>>

; CTRL+ALT+n   
^!n::                       
Send, ^c
IfWinExist, notes
{    
    WinActivate
}
else
{
    Run winword
}
WinWaitActive, notes
Send, ^v`n`n
return





This blog post lists a number of slightly more advanced AutoHotkey scripts that are particularly useful to translators as well as other computer users. They are designed to save time and take the dullness out of performing repetitive computing tasks, for example when taking screenshots, writing messages or entering special symbols.  I hope you like them and they will make your life a bit easier!


Check out my other blog posts about AutoHotkey:
 
Working more efficiently with AutoHotkey (part 1)
Working more efficiently with AutoHotkey (part 3)