2

In Windows (XP, 7, 8) how do you quickly assign keyboard shortcuts to launch your favorite applications using autohotkey when the application is active.

In Keyboard utilities, you can launch your favorite applications for fast access, by simply pressing a hotkey.

I was wandering if that could be done using autohotkey as well.

Edited:

Normally to add a script that when Ctrl+Alt+N is pressed, Notepad will be launched. You would need to have the following script.

^!n:: Run Notepad

What I want is that when the application is active, pressing Ctrl + Shift + A should take the path where the application is installed and create a script like above.

So when Command Prompt is active, pressing Ctrl + Shift + A should create a script like the following.

^!t:: Run C:\WINDOWS\system32\cmd.exe

where C:\WINDOWS\system32\cmd.exe is the path where cmd is installed/located

and Ctrl + Shift + T is the keyboard shortcut.

2
  • Yes, it is windows (XP, 7, 8)
    – Ishan
    Dec 27, 2012 at 22:37
  • Added it to the question ;)
    – Everett
    Dec 27, 2012 at 23:01

3 Answers 3

1

This isn't something you can do easily.

You could do something like: https://stackoverflow.com/questions/12851677/dynamically-create-autohotkey-hotkey-to-function-subroutine

Or you could modify your file at runtime and reload it.

#SingleInstance Force
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

^!n::
    WinGet, pn, ProcessName, A
    path := GetProcessPath(pn)
    tooltip, press a new hotkey
    Input, new_hotkey, L1
    tooltip,

    code = ^!%new_hotkey%`:`:Run, %path%`n
    FileAppend, %code%, %A_ScriptFullPath%

    Reload
    Sleep 1000 ; If successful, the reload will close this instance during the Sleep, so the line below will never be reached.
    MsgBox, 4,, The script could not be reloaded. Would you like to open it for editing?
    IfMsgBox, Yes, Edit
    return


GetProcessPath(exe) {
    ;;http://www.autohotkey.com/board/topic/32965-getting-file-path-of-a-running-process/
    for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process where name ='" exe "'")
        return process.ExecutablePath
}

return

Hotkeys:
^!f::Run, C:\Program Files\Mozilla Firefox\firefox.exe
0

Yes, you can. The following example will launch explorer when Win+0 is pressed (# denotes the Window key in AHK):

#0::Run C:\Windows\System32\explorer.exe

If the application does not launch because it is already running, you could create a batch file containing:

start program.exe

And tell the AHK script to launch that batch file.

2
  • I already knew how to do that but this is not what I am after. Your solution requires to actually find the application path and then create a keyboard shortcuts from it. Please have a look at the youtube.com/watch?v=GzcQbrkdvJU&feature=player_embedded to illustrate what I am after but using autohotkey instead of PhraseExpander which the video uses.
    – Ishan
    Dec 27, 2012 at 3:35
  • So you're after a GUI to create shortcut assignments?
    – Suchipi
    Dec 27, 2012 at 20:38
0

To quickly assign keyboard shortcuts to launch my favorite applications, I created an AutoHotkey script very easy to use and configure that allow to Open, Minimize or Restore a Window App, a Chrome App or a Chrome shortcut. It also has some other features like Error catching etc.. the code is here: https://github.com/JuanmaMenendez/AutoHotkey-script-Open-Show-Apps

Configuration Examples

F7:: OpenOrShowAppBasedOnExeName("C:\Windows\System32\SnippingTool.exe")

F8:: OpenOrShowAppBasedOnWindowTitle("Gmail", "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --app=https://mail.google.com/mail/")

I hope you found it helpful ;) 💁‍♂️⭐

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .