8

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
Shane
  • 368
  • 1
  • 4
  • 13

7 Answers7

6

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).

Chris Pfohl
  • 18,220
  • 9
  • 68
  • 111
  • How do you ensure that you have Alt-Tabbed to the correct window? – PleaseStand Dec 28 '10 at 23:23
  • AltTab was just 'for example' There is a way (althoguh I don't know what it is) to select a specific window...one sec. – Chris Pfohl Dec 28 '10 at 23:24
  • Yeah, not sure. That would be an excellent question to ask. I'll edit the response. – Chris Pfohl Dec 28 '10 at 23:26
  • I think this could be the solution except when I do hit the hotkey - instead of doing the action it types "F5AltTabF5" into the editor, F5 is my Save All command in npp. – Shane Dec 28 '10 at 23:43
2

There is also a free open-source plug-in for Notepad++ called RefreshBrowser that will refresh the browser when you save documents.

AimFireReady
  • 81
  • 2
  • 14
hikki
  • 31
  • 1
  • You are just promoting a commercial product. Therefore you answer has to be considered as spam. – honk Nov 29 '14 at 20:46
  • Appears free to me. They even have the source code link on their site. I tried it out and it works exactly as expected! Just copy the dll to your plugins folder. Easiest solution I have found. – dmikester1 Sep 05 '15 at 05:51
  • It was commercial - now its free. And its the best thing to have if you code with npp because it refreshes every browser you have open. (configurable). –  Nov 26 '15 at 16:43
1

This is the script I use. Then you just need to have the page you are working on in the current chrome tab, and its Win+Enter to compile-run your webapp/site from npp. I paste the snippet into one context that does some other things too, like arranging my windows. (I keep npp up with explorer++ on the side, then chrome open on my second monitor)

#IfWinActive ahk_exe Notepad++.exe
    #Enter::
        Send ^+s
        WinActivate ahk_exe chrome.exe
        Send {F5}   
    return

I think you want this

#IfWinActive ahk_exe Notepad++.exe
    #Enter::
        Send {F5}
        WinActivate ahk_exe chrome.exe
        Send {F5}   
    return
Kyle Zimmer
  • 300
  • 2
  • 7
1

I am not sure if this helps, but for me this was a great thing. I was creating a website on notepad++ but it was really annoying to save the html file and go to browser tab, and finally hit refresh to reflect the changes made in my code, on browser.
What I did was introduce a meta-tag, inside the head tags of the html files, while creating them initially, thereby, instructing the browser to refresh after fixed intervals of time. The meta tag is:

<meta http-equiv="refresh" content="10" >

So finally the html file would be something like this:

<!DOCTYPE html>
<html>
  <head> 
    <meta http-equiv="refresh" content="10" >
  </head>
  <body>
    Hello There!
  </body>
</html>

Here the content value instructs the browser after how many seconds it's going to refresh. In my case it's 10 seconds. So, at any point I save my html file after editing it in notepad, I wait for at most 10 seconds to see the changes my edit has brought into the html file. You can remove the tags later (simply run a script!). In my case, while using bootstrap css, this technique has saved me a lot of time and effort. Hope this helps.

Code-Zing
  • 41
  • 1
1

Use WinAutomation or its free cousin AutoIt. Both provide hotkey and window title search.

mth
  • 490
  • 2
  • 12
0

I use TypeItIn for all of my efficiency needs -- whether it's for specific code snippets or macros and other repeatable tasks.

Right now I'm doing a lot of editing of files in a specific directory. The following button activates Notepad++, saves the file, switches over to the correct tab in Google Chrome, and reloads the page. The script gets called when I use the keyboard shortcut, or when I Ctrl-click on the Notepad++ Window Title.

Button Details:

Name: Save and Reload

Watch for window title: Notepad++
  Match anywhere: Anywhere in Title

Shortcut Key: Alt+Shift+A

Text to be typed:
{Activate Notepad*}{Ctrl s}{Var1 Window}{Var1 Replace *C:\Program Files\Apache\apache-tomcat-6.0.37\webapps\essential_viewer\|}
{Var1 Replace C:\Program Files\Apache\apache-tomcat-6.0.37\webapps\essential_viewer\|}
{Var1 Replace  - Notepad++|}
{Activate localhost:8080/essential_viewer/{Var1} - Google Chrome}{BrowserRefresh}

Notes:

  1. Remove all whitespace from the text to be typed above, otherwise it will put newlines in your file.
  2. Activate Notepad* will put Notepad++ in focus. You can change {Ctrl s} to {Ctrl {Shift s}} to save-all if needed.
  3. It stores the window title (of the current file) in the variable "Var1". To be sure that it captures both saved and unsaved files, just in case, it does a replace twice for the file path. Once for and once for *. It then removes the trailing " - Notepad++".
  4. The Google Chrome window with the specific title is put into focus and that page alone is refreshed.

Hope this helps!

Community
  • 1
  • 1
rishimaharaj
  • 1,644
  • 2
  • 19
  • 34
0

I'm using Kyle Zimmer AHK script and previously I was using:

^s::           ;Binds the hot key to "Shift, S"
    Send ^+s    ;Pushes "Ctl,Shift, S"
    Send !{TAB} ; TAB to other window
    Sleep 50
    Send {F5}     ;Pushes "F5" to refresh
    Sleep 50
    Send !{TAB} ; TAB to original window
Yves Lange
  • 3,914
  • 3
  • 21
  • 33