AutoHotKey Scripting Basics – The Run Command

I have already used the Run command in two of my previous posts: Launching Google and Launching Calculator using AutoHotKeys.

The Run command is used to launch a program, document, URL, and even shortcuts.

Most of you must already be familiar with the Windows version of the Run Command. If you are not, try this:

Click the Start button on Windows then type “Run” then hit “Enter“.

A Run command window will now open; just type in the name of the program or complete URL of the Web site you want to open. For documents, however, you need to specify the complete path like “C:\My Documents\Meghna.doc”

AutoHotKeys allows you to have lot more fun with the Run command. You can launch multiple programs or Web sites at once, choose how they open, specify working directories, pass parameters etc.

Let me just start off with showing you one of its simplest uses: Launching multiple programs at once.

#m::
Run Notepad.exe
Run www.yahoo.com
Run Calc.exe
Run www.google.com
return

The above script will open the notepad, calculator and the home pages of both yahoo and google as soon as you press the Windows+m keys on your keyboard. Since AutoHotKeys executes scripts top-down, the programs will open in that order, so you can of course write them in order of your own preference.

The above script is an example of a multi-command line script and that is why we have put the commands beneath the hotkey definition. This improves readability and makes it easier to modify the scripts later, especially for larger scripts.

The Return command will exit the script (you will understand its real importance later). In single-line scripts, using the return command was unnecessary as exit was implied.

Let’s see another variation of the above script:

#m::
Run Notepad.exe, , max
Run www.yahoo.com
Run Calc.exe
Run www.google.com, , min
return

Now when you use this script, the Notepad will open maximized on your screen, while the google browser window will be minimized.

Meghna

7 thoughts on “AutoHotKey Scripting Basics – The Run Command”

  1. I have not heard that wordpad is a document. It is a executable treated as an executable by windows as all executables. What the problem is, however, is that it is not in the current path. It exists in program files\windows NT\accesories. Notepad exists in windows\system32.

    Adding the path to wordpad makes it accessible from the run command.

    It is not treated as a document.

    Reply
    • You are right, WordPad is not a document and is indeed a program accessible with the Run command. There is no need, however, to add the path since Wordpad does exist in the System directory. “Microsoft Word” (not WordPad) is recognized as a folder (not as a “document”) because 1. since the expression has a space in it, the first word (Microsoft) is considered and the others (Word) are arguments; and 2. “Microsoft” is a folder in the System directory. Thus the folder opens. If you want to start a Microsoft Office program from the command line, you may want to either add write the full path between quotes, or use the executable name: winword, excel, powerpnt, outlook, msaccess, onenote.

      Reply
  2. Hi,

    #m::
    Run Notepad.exe
    Run http://www.yahoo.com
    Run Calc.exe
    Run http://www.google.com
    return

    The above mentioned script, i have copied in to notepad and save it as s.ahk.
    after that i have compiled the script.
    After that i have selected run script

    But no action is performed by this script .(In Winows 7 i am executed this script).

    I am excepting after running this script
    notpad,yahoo,cc,google is able to open but nothing is happned. Can you please let me know what is the problem.

    Reply

Leave a Comment