Search code examples
editor

Save then refresh browser shortcut trick command in editor


I would like a hotkey to Save All in Notepad++ then switch to the browser and refresh the page. I have to do this thousands of times a day and doing the Save All hotkey, then Alt-Tab to the right window, then F5 to refresh again and again, there must be a better solution? I am open to switching editors if there is another that can do this.

I have tried using run commands but the problem is although it allows you to make something like [firefox.exe "current file"], if you come down to wanting to open it at a web address like localhost because it needs to run server side, then you have to manually specify the other part of the string, like [chrome.exe "custom var(web address) / filename"] and it always opens a new tab, then creates lots of clutter. Also, if you are editing an include file then it will try to open that instead of the page you want to see when you use the run command, a refresh would be the only realistic method I can think of using.

Edit: I got Cpfohl solution to work! If you have another method please share, as I will monitor this thread still.

Esc::                ; The hotkey I like to use
SetTitleMatchMode, 2 ; Match Partial Title Mode
SetKeyDelay 10, 10   ; Set Keystroke Delays
Send {F5}            ; Save All In Editor / I set to F5 in npp
IfWinExist, Firefox
   WinActivate
Send {F5}            ; Refresh Browser

Solution

  • I use AutoHotKey for this kind of stuff, but I'm pretty new at it. The nice part is that you don't have to switch editors. AutoHotKey lets you do anything that you want (pretty much), but it's easiest to use it to do things you can do with a relatively rote series of keystrokes.

    You'd write a script that you'd run at runtime. Then whenever you use your selected hotkey it executes the script (which can be made up of 'artificial' key-strokes).

    An example script might be (THIS IS UNTESTED AND ASSUMES THAT THE LAST WINDOW YOU HAD OPEN WAS THE BROWSER, i.e.: that "AltTab" causes the browser to open):

    !+s::           ;Binds the hot key to "Alt,Shift, S"
        Send ^+s    ;Pushes "Ctl,Shift, S"
        Send AltTab ;Pushes "Alt, Tab"
        Send F5     ;Pushes "F5"
    

    EDIT 05/2020

    I'd like to call out that nowadays there are much better options than this. Hot reloading is a solved problem by whatever build tool you're using (rollup, webpack, etc), or by whatever file server you're using to host your files locally (e.g. https://github.com/tapio/live-server).