Skip to content

Instantly share code, notes, and snippets.

@noahcoad
Last active October 12, 2015 17:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save noahcoad/4064637 to your computer and use it in GitHub Desktop.
Opens Notepad with hotkeys
;
; Hotkey to opens text editor with clipboard contents
;
; Win+W Open text editor with empty temp file
; Win+Shift+W Open text editor with clipboard contents in an temp file
;
; See blog post for more info:
; http://noahcoad.com/post/411/hotkey-to-open-clipboard-contents-in-text-editor
;
; Get this little app and update the path to where you put it
; Download from here: https://github.com/noahcoad/EditClipboardText/blob/master/build/EditClipboardText.zip?raw=true
cliputil := "c:\noah\tools\coad\EditClipboardText.exe"
; Automate dialogs
#Persistent
SetTitleMatchMode, 2
SetTimer, AppDialogAutomation, 350
return
; Open favorite text editor w Win+W
#w::
_file := MakeTempFile("txt")
Run %_file%
return
; Save the clipboard contents to a temp file and open the text file w Win+Shift+W
#+w:: Run %cliputil%
AppDialogAutomation:
; Some common text editors
; You can comment out the editors not used
; Window's notepad.exe and SlickEdit are supported as they
; do not provide the filename in the save dialog to automation
; Notepad2 or Notepad2-mod, always save temp files
SendIfWinActiveExtended("Notepad2 ahk_class #32770", ".*Save changes to .*\\tmp.{2,6}\.txt.\?", "!y", true, 0, 0, true)
; UltraEdit, always save temp files
SendIfWinActiveExtended("UltraEdit ahk_class #32770", ".*\\tmp.{2,6}\.txt", "!y", true, 0, 0, true)
; Notepad++, always save temp files
SendIfWinActiveExtended("Save ahk_class #32770", "Save file .*\\tmp.{2,6}\.txt. \?", "!y", true, 0, 0, true)
; Sublime Text 2, always save temp files
; Alternatively you could set the setting save_on_focus_lost = true
; See here for info: http://noahcoad.com/post/391/favorite-sublime-text-2-user-settings
SendIfWinActiveExtended("Save Changes? ahk_class #32770", "tmp.{2,6}\.txt has been modified, save changes\?", "!y", true, 0, 0, true)
return
; Sends a keystroke to a dialog
SendIfWinActiveExtended(title, text, keys, regex, targetWidth, targetHeight, force)
{
savedA_TitleMatchMode=%A_TitleMatchMode%
if (regex)
SetTitleMatchMode RegEx
if (force)
WinActivate %title%, %text%
IfWinActive %title%, %text%
{
if (width > 0 and height > 0)
{
WinGetActiveStats, Title, Width, Height, X, Y
if (targetWidth = Width and targetHeight = Height)
Send %keys%
} else {
Send %keys%
}
}
SetTitleMatchMode %savedA_TitleMatchMode%
}
; Creates a temporary file with the given extension
MakeTempFile(_ext)
{
_count = 0;
Loop {
_count++
_count = 000000%_count%
StringRight,_count,_count,4
_file = tmp%_count%.%_ext%
_file = %temp%\%_file%
IfNotExist %_file%
break
}
FileAppend,,%_file%
return %_file%
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment