Choosing to open a file with a specific program Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Elermino
Posts: 114
Joined: 29 Nov 2021, 17:43

Choosing to open a file with a specific program

Post by Elermino » 20 Jan 2022, 09:45

When selecting a file and pressing a key combination, I want it to give me the option to choose which program to open it with.
Thanks in advance!

User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: Choosing to open a file with a specific program

Post by mikeyww » 20 Jan 2022, 10:08

Code: Select all

prog := ["notepad.exe", "chrome.exe"]
SetTitleMatchMode, RegEx
Menu, progs, Add, Open in Notepad, Open
Menu, progs, Add, Open in Chrome, Open

#IfWinActive ahk_class (Cabinet|Explore)WClass
F3::Menu, progs, Show
#IfWinActive

Open:
For each, file in getSelected()
 Run, % prog[A_ThisMenuItemPos] " """ file """"
Return

getSelected() { ; https://www.autohotkey.com/boards/viewtopic.php?style=17&t=60403#p255256 by teadrinker
 hwnd := WinExist("A"), selection := []
 WinGetClass, class
 If (class ~= "(Cabinet|Explore)WClass")
  For window in ComObjCreate("Shell.Application").Windows
   If (window.hwnd = hwnd)
    For item in window.document.SelectedItems
     selection.Push(item.Path)
 Return selection
}

User avatar
Elermino
Posts: 114
Joined: 29 Nov 2021, 17:43

Re: Choosing to open a file with a specific program

Post by Elermino » 20 Jan 2022, 10:25

mikeyww wrote:
20 Jan 2022, 10:08

Code: Select all

prog := ["notepad.exe", "chrome.exe"]
Menu, progs, Add, Open in Notepad, Open
Menu, progs, Add, Open in Chrome, Open

#If explorer()
F3::Menu, progs, Show
#If

Open:
For each, file in getSelected()
 Run, % prog[A_ThisMenuItemPos] " """ file """"
Return

getSelected() { ; https://www.autohotkey.com/boards/viewtopic.php?style=17&t=60403#p255256 by teadrinker
 hwnd := WinExist("A"), selection := []
 For window in ComObjCreate("Shell.Application").Windows
  If (window.hwnd = hwnd)
   For item in window.document.SelectedItems
    selection.Push(item.Path)
 Return selection
}

explorer() {
 WinGetClass, class, A
 Return class ~= "(Cabinet|Explore)WClass"
}
Alternative: right-click -> "Open with..."
It works well. Is there a way to make it work on desktop as well?

User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: Choosing to open a file with a specific program  Topic is solved

Post by mikeyww » 20 Jan 2022, 10:49

Code: Select all

prog := ["notepad.exe", "chrome.exe"]
SetTitleMatchMode, RegEx
Menu, progs, Add, Open in Notepad, Open
Menu, progs, Add, Open in Chrome, Open

#IfWinActive ahk_class CabinetWClass|ExploreWClass|WorkerW|Progman
F3::Menu, progs, Show
#IfWinActive

Open:
For each, file in getSelected()
 Run, % prog[A_ThisMenuItemPos] " """ file """"
Return

getSelected() { ; https://www.autohotkey.com/boards/viewtopic.php?style=17&t=60403#p255256
 hwnd := WinExist("A"), selection := []
 WinGetClass, class
 Switch
 { Case class ~= "(Cabinet|Explore)WClass":
    For window in ComObjCreate("Shell.Application").Windows
     If (window.hwnd = hwnd)
      For item in window.document.SelectedItems
       selection.Push(item.Path)
   Case class ~= "Progman|WorkerW": ; https://www.autohotkey.com/boards/viewtopic.php?p=154836#p154836
    oWindows := ComObjCreate("Shell.Application").Windows, VarSetCapacity(hWnd, 4, 0)
    oWin := oWindows.FindWindowSW(0, "", SWC_DESKTOP := 8, ComObject(0x4003, &hWnd), SWFO_NEEDDISPATCH := 1)
    For oItem in oWin.Document.SelectedItems
     If SubStr(oItem.path, 1, 3) != "::{"
      selection.Push(oItem.Path)
 }
 Return selection
}

Post Reply

Return to “Ask for Help (v1)”