Need a "one-click" webdev hotkey workflow solution

148 views Asked by At

Question for all you webdev guys/gals who have found a minimal-hassle development environment.

  • OS: Win7
  • Editor: JEdit
  • Task: Previewing work in a web browser

I would like to program a single hotkey to pack the following series of hotkeys into one. I use this sequence many times a day to preview my work in a browser.

The key commands are:

  • (from JEdit) ctrl + e ctrl + s [save all files]
  • (win) alt + tab [switch me over to browser]
  • (browser) ctrl + r [reload page]

I have not used Dreamweaver or flash in years but I remember punching f12 or ctrl + enter and having a browser pull up previewing the current work file. I am looking for a similar workflow but I cannot simply link to the saved file on disk. I need to look at the file through a local webserver. Typically I just have the browser open to the page I need and refresh it when I need to preview what I have done.

Another issue is the alt+tab step is not explicit enough. Often times the browser is not correctly sequenced in the open apps list to get to it without multiple tabs.

Thanks for any suggestions, workflow tips, etc.

2

There are 2 answers

1
Ross Rogers On

  • Use this answer to create a command line method of refreshing a webpage ( it will work for any browser).
  • Next, create a baseline macro in JEdit for activating that script that you created:
    • In JEdit, you can record macros with Macros->Record Macro.
    • Do ctrl + e + s
    • Stop recording the macro with Macros->Stop Recording.
  • Open the JEdit browser tab with the newly created macro buffer that is now open in JEdit and add a system call at the end of it to run your visual basic script for refreshing the browser tab:

    Runtime.getRuntime().exec("c:/PATH/TO/VB_SCRIPT AND ARGS IF YOU NEED THEM");
    

  • Save the macro.
  • Create a JEdit keyboard shortcut with utilities->global options, select "Shortcuts" then search for you macro and create a new keyboard binding.

Note that the Java beanshell exec command is non-blocking, so if you want to do anything else after executing the command, you may have to insert a sleep like:

Thread.currentThread().sleep(2000);
0
margenn On

Just Press Alt + F5 and get it done!

To accomplish that, install AutoHotKey and run the script below (copy in a text file and change extension to .ahk). There is a portable version here. It was tested with AutoHotKey version is 1.0.48.05

This solution is pretty flexible since you can change Keys, Editors, Browsers and everything else. It works with Firefox and IE but you can easily customize.

The varTextEditor and varBrowsers where discovered using "WindowSpy" utility that comes bundled into AutoHotKey.

;###############################################################################
; Save all unsaved documents, refresh all opened browsers and return to text editor
;###############################################################################
!F5::
    ;Configuration vars. Edit here the settings of this script
    ;               jEdit       Eclipse
    varTextEditor = SunAwtFrame,SWT_Window0
    ;varBrowsers = MozillaUIWindowClass,MozillaWindowClass,Chrome_WidgetWin_0,IEFrame,OpWindow,{1C03B488-D53B-4a81-97F8-754559640193}
    ;             Firefox3             Firefox4            Chrome             IEca    Opera    Safari
    varBrowsers = MozillaWindowClass,IEFrame
    ;End of configuration vars.

    WinGetClass, thisWindowClass, A ;Get the active window class

    if (InStr(varTextEditor, thisWindowClass, true, 1) > 0) { ;true = case sensitive
        varTextEditorClass = ahk_class %thisWindowClass%
        if (thisWindowClass = "SunAwtFrame") {
            OutputDebug, ...Saving everything
            ; SetKeyDelay, 100, 100, Play
            Send ^+s  ;Ctrl + Shift + S = Save all
        } else if (thisWindowClass = "SWT_Window0") {
            SendPlay ^s ;Ctrl + S = Save
        }
        Sleep, 500 ;Give some time to the data be recorded on hard disk
    } else {
        MsgBox, 0, Ops!, You must be in on these text editors: (%varTextEditor%) to get this script running, 5
        return
    }

    ;Refresh all opened (and maximized) browsers
    Loop, parse, varBrowsers, `,
    {
        varClasseBrowser = ahk_class %A_LoopField%
        if WinExist(varClasseBrowser) {
            WinGet, winState, MinMax, %varClasseBrowser% ;get window state. -1 = minimized
            if (winState != -1) {
                WinActivate, %varClasseBrowser%
                OutputDebug, ...Refresh browser %A_LoopField%
                Send, {F5}
            }
        }
    }
    ;Return to text editor
    WinActivate, %varTextEditorClass%
return