Skip to content

Instantly share code, notes, and snippets.

@wings27
Created September 15, 2016 10:21
Show Gist options
  • Save wings27/f2880c25d41b70939ac06672bf3f8abf to your computer and use it in GitHub Desktop.
Save wings27/f2880c25d41b70939ac06672bf3f8abf to your computer and use it in GitHub Desktop.
replace notepad with SublimeText using Windows IFEO
import os.path
import subprocess as sp
import sys
import time
def main():
new_notepad = 'C:\\Program Files\\Sublime Text 3\\sublime_text.exe'
args = sys.argv[2:] # ignore the first arg (this script itself) and the second arg (original notepad.exe)
path = guess_path(args)
if path:
sp.Popen([new_notepad, path])
else:
sp.Popen(new_notepad)
def guess_path(args):
if len(args) == 0:
return None
path = ' '.join(args)
if os.path.isfile(path):
return path
else:
print('ERROR: Path not exist: ' + path)
print('multiple continuous spaces in path?')
return None
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment