Skip to content

Instantly share code, notes, and snippets.

Last active March 13, 2016 02:38
Show Gist options
  • Save xgvargas/34514b32e6c1eb842d19 to your computer and use it in GitHub Desktop.
Save xgvargas/34514b32e6c1eb842d19 to your computer and use it in GitHub Desktop.
Windows batch file association


Generates two windows .reg file to install and uninstall a collection of associations for your prefered software.

Also, you can configure it to include:

  • create new file (for any file of your collection)
  • Open with... when right click a file
  • Open with... when right click a folder
  • Open with... when right click an empty area inside a opened folder.

And for each association you can define the icon and description of each file type.

⚠️ To put it clear: It will not touch your Windows registry, all it does is to create a .reg file with your configuration. Is up to you to check everything and then apply the changes by double clicking the .reg file or by importing it into regedit.exe.

# the base path for all .ico files
iconpath: D:\Projetos\small-tools\XIcon\ico\
programs: # a list of programs
- exec: C:\Users\Gustavo\AppData\Local\atom\app-1.5.4\atom.exe # full path to executable
# optional to create Open with...
# mandatory
name: atom # unique name for this program
# optional (remove declaration to suppress creation of registry)
file: Open File in Atom # text for "Open with..." for files
folder: Open Folder in Atom # text for "Open with..." for folders
background: Open Folder in Atom # text for "Open with..." for background area
# list of file types:
# [extension, description, iconfile.ico, newContext] the last one is optional
- [txt, Texto, txt.ico, True]
- [h, Header, h.ico]
- [hpp, Header, hpp.ico]
- [c, C, c.ico]
- [cpp, C++, cpp.ico]
- [vhd, VHDL, vhd.ico]
- [vhdl, VHDL, vhd.ico]
- [asm, Assembly, asm.ico]
- [java, Java, java.ico]
- [php, PHP, php.ico]
- [js, Javascript, js.ico]
- [css, Estilos, css.ico]
- [less, Estilos, less.ico]
- [sass, Estilos, sass.ico]
- [scss, Estilos, scss.ico]
- [ts, Typescript, ts.ico]
- [xml, XML, xml.ico]
- [json, JSON, json.ico]
- [yaml, YAML, yaml.ico]
- [sql, SQL, geral.ico]
# - [lst, Listagem, lst.ico]
- [rst, reStructuredText, rst.ico]
- [md, Markdown, md.ico, True]
#! /usr/bin/env python
# -*- coding: utf-8 -*-
template_intro = '''Windows Registry Editor Version 5.00
; Please review all this file BEFORE apply changes to your system.
; I'm NOT responsable for any damage caused to your system.
template_reg = '''
\n; cria associacao de {descr} <.{ext}>
"Content Type"="text/plain"
@="{executable} \\"%1\\""'''
template_new = '''
\n; inclue <.{ext}> na lista de opcao do menu "Novo" do botao direito
template_unreg = '''
\n; remove associacao de <.{ext}>
template_context_file = '''
\n; quando clica botao direito num arquivo
@="{executable} \"%1\""'''
template_context_file_unreg = '''
\n; remove clique direito num arquivo
template_context_folder = '''
\n; quando clica botao direito numa pasta
@="{executable} \"%1\""'''
template_context_folder_unreg = '''
\n; remove clique direito num folder
template_context_background = '''
\n; quando clica botao direito numa parte vazia de uma pasta aberta
@="{executable} \"%V\""'''
template_context_background_unreg = '''
\n; remove clique direito numa parte vazia da pasta
# --------------------------------------------------------------------------------------
import yaml
data = yaml.load(open('assoc.yaml', 'r'))
reg = open('register.reg', 'wt')
unreg = open('unregister.reg', 'wt')
iconpath = repr(data['iconpath'])[1:-1]
for prog in data['programs']:
executable = repr(prog['exec'])[1:-1]
if 'context' in prog:
if 'name' in prog['context']:
if 'file' in prog['context']:
r = template_context_file.format(name=prog['context']['name'], caption=prog['context']['file'], executable=executable)
u = template_context_file_unreg.format(name=prog['context']['name'])
if 'folder' in prog['context']:
r = template_context_folder.format(name=prog['context']['name'], caption=prog['context']['folder'], executable=executable)
u = template_context_folder_unreg.format(name=prog['context']['name'])
if 'background' in prog['context']:
r = template_context_background.format(name=prog['context']['name'], caption=prog['context']['background'], executable=executable)
u = template_context_background_unreg.format(name=prog['context']['name'])
for ext in prog['extensions']:
r = template_reg.format(ext=ext[0], descr=ext[1], iconpath=iconpath, icon=ext[2], executable=executable)
if len(ext) == 4:
if ext[3]:
n = template_new.format(ext=ext[0])
u = template_unreg.format(ext=ext[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment