Edited 5/28/15 to add:
OK, I think this latest code (rev. 5/27/15) is golden now. At least, it works well for me. Comments/bug reports welcome -- please post in this thread.
Hi, I'm new to the forum (as of 21 May 2015) and relatively new to AutoHotkey (been using it lightly for about a year prior to that date). Being a product of the DOS era, I generally prefer typing commands to mousing around. I recently wrote a simple AHK script for issuing commands to Windows. I call it WinRun. When you hit the hotkey (default is NumPadAdd), an Input box is displayed, in which you can enter any of the following:
- Program name -- to launch a program
- File name or URL -- to open a file or other resource in its associated Windows application
- Window title fragment -- to switch to an open window whose title contains the fragment
- Alias -- an abbreviation for any of the above. You create aliases yourself in a plain-text file called WinRun.ini. For example: G=http://www.google.com/ Then you can enter G in the Input box to go to the Google home page. (User-created aliases are the most useful -- and addictive -- way to use WinRun, IMHO.)
- Call to WinRun-L.ahk library of AHK routines. This library contains a few basic window-manipulation subroutines -- you can add your own.
Command-line usage
WinRun.ahk w h x y
Optional parameters w and h set the width and height of the Input box
Optional parameters x and y set the screen position of the Input box
To specify the default values for some parameters but not others, use a dot. For example:
WinRun.ahk . . 0 0
You can download the latest version of the complete package, including source code, compiled EXEcutable, sample WinRun.ini file, WinRun-L.ahk library file and documentation, here:
http://users.datarea.../ammaze/winrun/
Below is the source code for the script (WinRun.ahk). Feedback from experienced AutoHotkey users -- or anyone -- would be much appreciated.
Revision History
05/27/2015
Restored functionality whereby only command or alias that contains ":" or "." is Run; other commands and aliases are treated as window title fragments and WinRun attempts to switch to an active window whose title contains the fragment (see WinRun.txt)
05/26/2015
Coding economies in source. WinRun.exe is also smaller (new, smaller icon file)
Fixed bug relating to .ini variable [AutoExe] when script is run via WinRun.exe.
05/25/2015
WinRun.exe compressed with upx.exe
Added var [AutoExe] for use in WinRun.ini. [AutoExe] refers to full path to AutoHotkey.exe (if AutoHotkey is installed), or to a copy of AutoHotkey.exe present in the the script directory (A_ScriptDir) if the script is run via WinRun.exe.
05/24/2015 and earlier
Miscellaneous tweaks.
; *********************************************************** ; WinRun.ahk -- AutoHotkey [CLD rev.5/27/2015] ; Open|Switch_to program, URL, folder, etc., etc. ; ; AutoHotkey version 1.1.22.00 ; ; Create aliases (command abbreviations) in WinRun.INI ; Enter "ini" (no quotes) to edit WinRun.INI ; Run AutoHotkey subroutines from WinRun-L.ahk library file ; Sample INI entry: ; MyR=[LibFile] MyRoutine ; runs "MyRoutine:" in WinRun-L.ahk ; WinRun.txt has additional information ; *********************************************************** ; ; ----------------------------------------------- ; ; Hotkey assignment: NumPadAdd:: ; ; See bottom of file for "Quit" hotkey assignment ; ----------------------------------------------- ; ; Input Box dimensions and screen position ; Can set on command line with WinRun.ahk [width] [height] [X] [Y] width = 300 height = 130 ; Leave blank to center Input Box on screen X = Y = ; X, Y settings for upper left-hand corner of desktop: ;X = 0 ;Y = 0 ; ----------------------------------------------- ; var1 = %1% var2 = %2% var3 = %3% var4 = %4% If var1 is integer width = %var1% If var2 is integer height = %var2% If var3 is integer X = %var3% If var4 is integer Y = %var4% var1 = var2 = var3 = var4 = ; ; ---------------------------------- ; #NoEnv #Persistent #SingleInstance force #WinActivateForce DetectHiddenText, On DetectHiddenWindows, On SetBatchLines -1 SetTitleMatchMode, RegEx SendMode Input SetWorkingDir %A_ScriptDir% StringCaseSense, Off SplitPath, A_ScriptFullPath,,IniDir,,IniFile IniFile = %IniDir%\%IniFile%.ini LibFile = %IniDir%\WinRun-L.ahk If A_AhkPath AutoExe = %A_AhkPath% Else AutoExe = %A_ScriptDir%\AutoHotKey.exe WinGetTitle, CrntWin, A Input = Enter program name, window title, alias or "ini" ; Input Box InputBox, Input, WinRun (Shift-NumPadAdd Quits), %Input%,,%width%,%height%,%X%,%Y%,,60, If ErrorLevel or not Input { WinActivate, %CrntWin% Exit } StringUpper, TestIni, Input If TestIni = INI { Run, %IniFile% Exit } IniRead, KeyValue, %IniFile%, WinRun, %Input%, %A_Space% If KeyValue { If KeyValue contains [AutoExe] StringReplace, KeyValue, KeyValue, [AutoExe], %AutoExe%, All If KeyValue contains [LibFile] StringReplace, KeyValue, KeyValue, [LibFile], %LibFile%, All If KeyValue contains [IniDir] StringReplace, KeyValue, KeyValue, [IniDir], %IniDir%, All Input = %KeyValue% } If Input not contains .,: { IfWinExist, i).*%Input%.* { WinActivate, i).*%Input%.* } } Else Run, %Input% Exit ; ----------------------------------------------- ; Quit WinRun hotkey assignment: +NumPadAdd:: SendInput, {Esc} MsgBox, 64, WinRun, Quitting WinRun, 1 ExitApp ; *********************************************************** ; end WinRun.ahk