This script lets you launch a file with an ambiguous file extension, like
.sch, which is used
to represent many different formats for many different programs. Windows only lets you
associate files based on their extension. This script looks into the file itself and
determines what type it is, then launches the correct app, similar to the way Linux looks at magic numbers.
- superuser.com: Get Windows to treat files with the same extension differently
- Wikipedia: Magic numbers in files
Windows 7 doesn't let you associate with a script directly, but you can do it in the registry.
Associate it with something, then
regedit, go to
and add the script like
"C:\..python" "..script.py" "%1"
You can put in any bytes you want to make this work with any ambiguous file extension. None of the magic numbers can be a substring of another, or the wrong one might be recognized. Use a hex editor like HxD to open a bunch of files from the same app, and cycle through them looking for the first byte that changes. If you add more formats, please leave them in a comment here or fork it or whatever.
The paths aren't necessarily right. I don't actually have all of these installed right now.
This is in YAML format. The first indentation level is just a name for the program, then the path to the executable, and then the list of file signatures that it should open
Enclose paths and plain text signatures in single quotes
'like this' to avoid problems with slashes and colons
Enclosing text dumps in double quotes
"like this" allows use of C escapes like
Hex dumps are automatically recognized as long as each byte is separated by a space, like this:
49 49 02 04. (
10 by itself does not get recognized even though it fits the regex because YAML interprets it as an integer before it gets a chance to be regexed. So I had to use the
!hexdump tag for that one.)
Some of these file dumps are from personal testing, others from File Extension Seeker
- I got this compiling with cc_freeze, and moved the configuration into a .yml file, so post that version of the code.
- Try to make a single executable with bbfreeze instead
.brdfiles, too? Then it snowballs into handling any ambiguous extension with one program, though.
- Use python-magic/libmagic instead?
- More complex, but more powerful format
- Have to invent mime types for these schematic/PCB files
- Could be expanded to many file types, could become a Mini-Magic for Windows for any ambiguous file type? (But same icon for all those files? :/)
- Use balloon pop-ups instead of opening the Command Prompt window