0

Suppose I have two .pdf files. One is a comic book and the other is just a document. The behavior I want to achieve in the end is when I double click on the comic book, it will open the comic book reader software, but when I double click the plain document it will open it in the regular PDF reader.

To achieve this goal my idea is to intercept the 'open file' windows event and somehow inject a small script there. Maybe search for a pattern in the file path that's going to be open. Let's say all my comic books are in a /comic/ folder. So if the path contains the string comic I open it with the comic book reader and else I open it with whatever windows wanted to open it by default.

The bottom line is, how can you open different files with the same extension with different programs without going through the open with... menu?

I've seen an 'autohotkey' script that will open a file under the cursor in a specific program if you press a hotkey. This is somewhat a good solution, but I wonder if there's something better?

EDIT: Another idea is just to replace the default application in windows that opens PDFs with a script that does the above. IE, searches the path for a pattern and then opens it in a program according to its findings. Is something like that is possible?

5
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Nov 5, 2021 at 18:53
  • The simplest solution: Change the extension of all files you want to open with the second program to e.g. .pdf2, doubleclick one of them and select the second program in the "How do you want to open this file?" window.
    – Relax
    Nov 5, 2021 at 19:03
  • @user3419297 This will not work as the second program doesn't know what .pdf2 means. Your solution relies on the program figuring out what kind of file it tries to open regardless of extension. Usually this is not the case. Nov 6, 2021 at 15:03
  • On my system (Win 10) it works. You can change the default program in the properties of this file, in the menu item "Open with" or in the "How do you want to open this file?" window..
    – Relax
    Nov 6, 2021 at 15:15
  • @user3419297 You don't get me. You can tell Windows to open .txt2 files with Notepad. And it works because Notepad can figure out that it's a text file regardless of the extension. This is not true for most programs. Many programs rely on the extension to figure out how they should treat the files. So if they see an extension they don't know, they don't know how to handle it. Nov 6, 2021 at 16:19

1 Answer 1

1

Create a program in your preferred language which takes the file name as a command-line parameter, does some guessing – either based on the path alone, or on the PDF file's contents – and make Windows open all PDF files with that program. (In Windows I'd probably go for VBScript or Python due to them having "windowless" interpreters, and even AutoHotkey might work.)

This is the least hacky option – there is no magic "event interception" that needs to be done.

Before Microsoft Office went with OOXML (the .docx, .xlsx) formats, around Office 2003 it had the option to store documents as basic XML files. The file extension used was .xml regardless of the type – documents that opened in Word were .xml, spreadsheets that opened in Excel were .xml, and all the other random XML files that opened in Internet Explorer were .xml too.

The way this worked was that .xml files were associated with a dedicated "launcher" program which looked at the XML file's structure and opened either Word, Excel, or whatever else was appropriate.

1
  • This is what I ended up doing. I wrote a python script, made it an executable and then told windows to always open the specific files with the script. Nov 6, 2021 at 15:04

You must log in to answer this question.

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