Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from Nov 4 '11 at 15:25

This question came from our site for professional and enthusiast programmers.

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 Nov 6 '11 at 18:14
Do you have any web development experience? Will you find difficulty on searching your web development browser? – Kit Ho Nov 7 '11 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 Nov 7 '11 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 Nov 12 '11 at 13:39
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 Nov 12 '11 at 23:34

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"
    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"
    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

share|improve this answer
Do you have alternative solution for Linux env? – Kit Ho Nov 5 '11 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 Nov 6 '11 at 13:15

You must log in to answer this question.

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