4

I am doing web development, and I found that I always lose focus on the browser that I am doing development on.

I always open other browser windows at the same time for searching, writing, etc. So there are a lot of applications running at the same time.

Each time I wish to return to test my webpage on the development browser, I have used a lot to time for searching that particular browser.

What I want to do is press a short key --> automatically focus on the particular browser, and maybe do a refresh if it is possible.

How do I do that on a Linux machine?

5
  • Not an answer, but a suggestion : You could use the Linux Workspaces to put the important browser windows in another workspace, so you could switch to them at the click of the mouse. See for example this article : Add, Switch, And Change Workspace In Ubuntu Linux. !enter image description here
    – harrymc
    Commented Nov 6, 2011 at 18:14
  • Do you have any web development experience? Will you find difficulty on searching your web development browser?
    – Kit Ho
    Commented Nov 7, 2011 at 1:49
  • What I normally do for web development is use one browser session with tabs, and I always keep the tabs in the same order. If I use virtual machines to simulate the network, this serves to further separate the development and test environments. In Firefox you can also use these keyboard shortcuts for positioning between tabs, and especially the wonderful Firebug.
    – harrymc
    Commented Nov 7, 2011 at 7:21
  • I think this is actually the right answer. You create virtual Desktops and put the Browsers on different virtual Desktops. The default shortcuts to go to a desktop are STRG+F1 to STRG+F12 (On KDE at least). This way you could switch between browsers by putting them on different desktops. After the switch the top window on that desktop should automagically be activated.
    – Darokthar
    Commented Nov 12, 2011 at 13:39
  • 1
    Whether or not this can be easily done depends mainly on the Window Manager your system is using. Your question does not include this information. You did not even mention the distribution you are using.
    – jankes
    Commented Nov 12, 2011 at 23:34

1 Answer 1

1

Open Automator and select to create a Service that receives no input in any application. Double-click the Launch Application action and select your browser. Save as e.g. Go To Safari. This will work with any web browser. Launch Application will bring it to the front if it's already running.

enter image description here


If you want to also reload the frontmost tab, you need to use AppleScript in supported browsers. For Safari, replace Launch Application with Run AppleScript, and paste the following script code:

tell application "Safari"
    activate
    do JavaScript "window.location.reload();" in first document
end tell

This will focus Safari and reload the frontmost document.


To focus and reload Google Chrome, use the following AppleScript instead:

tell application "Google Chrome"
    activate
    reload active tab of first window
end tell

Firefox and Camino don't seem to have scripting capabilities to do this. But you can always fall back to OS X's accessibility API, e.g.

tell application "Safari" to activate
tell application "System Events" to keystroke "r" using command down

This will simply simulate a Cmd-R key press in the program you switched to in the first line.


If you want to select a particular window of your web browser, you can use something like the following, again using UI scripting:

tell application "Safari" to activate
tell application "System Events"
    tell application process "Safari"
        click menu item "Super User" of menu of menu bar item "Window" of menu bar 1
    end tell
end tell

This will programmatically click the menu item corresponding to a specific window in the standard Window menu in most applications.


To assign a keyboard shortcut, go to System Preferences » Keyboard » Keyboard Shortcuts » Services, select the Go To Safari service you just created, and assign a keyboard shortcut there.

Repeat for all browsers you want to do this in.

enter image description here

2
  • Do you have alternative solution for Linux env?
    – Kit Ho
    Commented Nov 5, 2011 at 17:25
  • @KitHo Your question didn't indicate for what OS you needed a solution. The scripting capabilities and their integration in the UI are one of the reasons I prefer OS X — I don't know how you'd do this on Linux.
    – Daniel Beck
    Commented Nov 6, 2011 at 13:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .