Monday, April 8, 2013

Notepad++: Launch Firefox, Chrome, IE to your heart's content

Somehow I lost my ability in Notepad++ to open a file in a web browser. I couldn't figure out how to get it back, so I turned to the internet and ran across a solution for people having difficultly setting it up with Google Chrome. I ended up just modifying their solution:



This post on super user (stack exchange) got me started, then I put together how to add Firefox, Chrome, and IE.
http://superuser.com/questions/306736/notepadis-there-a-way-to-fix-the-fact-that-i-cant-run-chrome-from-the-run-me

Shortcuts.xml

Notepad++ uses a "shortcuts.xml" file to store shortcut information. You'll have to poke around, but it's located in your AppData folder, here is where I found mine:
Win7: C:\Users\jmj\AppData\Roaming\Notepad++\

  • It's important to note that this file acts like a registry setting. When Notepad++ is started, it loads those settings into memory, then when it's closed it saves them back to the settings.xml file. This makes it so that you can't edit the shortcuts.xml file in Notepad++ itself because when you close the application it will over-write your changes to the file!
  • Unfortunately the best way to avoid this is to keep NPP closed and edit the file in (gasp!) notepad.exe

You place the commands in the < UserDefinedCommands > section, I've provided that section from my shortcuts.xml file below:
<UserDefinedCommands>
<Command name="Launch in Chrome"  Ctrl="yes" Alt="yes" Shift="yes" Key="82">%LocalAppData%\Google\Chrome\Application\Chrome.exe                       &quot;$(FULL_CURRENT_PATH)&quot;</Command>
<Command name="Launch in FireFox" Ctrl="yes" Alt="yes" Shift="yes" Key="83">&quot;C:\Program Files (x86)\Mozilla Firefox\firefox.exe&quot;    &quot;$(FULL_CURRENT_PATH)&quot;</Command>
<Command name="Launch in IE"      Ctrl="yes" Alt="yes" Shift="yes" Key="84">&quot;C:\Program Files (x86)\Internet Explorer\iexplore.exe&quot; &quot;$(FULL_CURRENT_PATH)&quot;</Command>
</UserDefinedCommands>

  • I copied the "Launch in Chrome" directly from the superuser.com website, then modified it for the remaining calls. 
  • I tried to line up the attributes above so that you can easily read them 
  • You can use the Shortcut Mapper to change the shortcut calls after you have these loading correctly (I haven't bothered yet) 
  • I had to use &quot; to handle spaces in the path (i.e. "C:\Program Files (x86)\Mozilla..") 
  • $(FULL_CURRENT_PATH) refers to the html file you are editting in NPP (ex: jasonjeromeresume.html from the screenshot) 

There are other commands available, read about them in the npp docs:
http://npp-community.tuxfamily.org/documentation/notepad-user-manual/commands

That's it!

4 comments:

  1. I did patch the full program path in the relevant line of the shortcut.xml file and it seems to work.

    ....C:\Program Files\Mozilla Firefox\firefox.exe

    instead of just firefox (default after install, no response whatesoever)

    Thanks

    ReplyDelete
  2. Glad you were able to figure it out, I tend to use more full-paths in all my scripts these days.

    ReplyDelete
  3. Would this actually start automation from the NotePad++ for the browsers or just list the actual code on the specific browser? I am trying to make the Python code run in NotePad++ to start up IE and Chrome browsers.

    ReplyDelete
    Replies
    1. The command makes use of parameters sent to the program. I.E. "firefox.exe mywebpage.html" instructs firefox to open "mywebpage.html". I'm not sure what you are asking about python, unless you are using a web framework like Django. If this is the case, I bet you could alter the command to have firefox interpret your file as a URL (localhost/myapp/mywebpage) instead of a vanilla file. I'd also bet you'll want to edit the file in the server folder (I'm assuming you are doing this all under a test environment). As usual, the best way to find out is to try.

      Delete