Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Let's say I have Safari active and I want to cycle between its open windows by pressing Safari's dock icon (instead of pressing cmd+>).

Is it possible to accomplish this somehow?

share|improve this question
add comment

4 Answers

There's no code in Dock.app to do this. command+` is the normal way to cycle through an application's open windows. If you want to cycle by clicking a dock icon, you could write an AppleScript to hit that keystroke and put that in the dock right next to Safari.

tell application "System Events"
    keystroke "`" using {command down}
end tell

Put the above into AppleScript Editor, and save it as an application. It won't work unless we prevent it from stealing focus, which can be accomplished by right-clicking the app bundle and showing package contents, open Contents/Info.plist, and then add the LSBackgroundOnly key (Application is background only) with a boolean value of 1. Add it to the dock and click it to execute that keystroke. It'll work for any application.

I find it a bit strange that you would think this is necessary or possible completely out of the blue. Is there something bigger that you're trying to accomplish with this?

share|improve this answer
    
+1 for the only realistic solution here, and for the last two sentences. –  Sasha Chedygov Nov 17 '10 at 4:55
add comment

You can right click on the dock icon and the menu will list all of the applications open windows.

share|improve this answer
    
Yeah, but I meant single clicking to cycle through them. If it's possible to bind that somehow. –  Krang Aug 9 '10 at 23:02
add comment

"Cmd >" ?

Why not use "Cmd `" (backtick, the key above the Tab), which is the standard one to cycle between windows for any app? If not, then you want to "bind" to something that you can single-click?

Edit: an easy built-in mouse-only approach is to set a Hot Corner in the System Preferences to show all Application Windows, then you can click on the one you want. But that doesn't "cycle".

share|improve this answer
add comment

The wanted behaviour can be achieved by replacing the Safari's icon in the dock with the following AppleScript (following NReilingh's example) saved as an Application:

tell application "Safari"
    activate
end tell

tell application "System Events"
    keystroke "`" using {command down}
end tell

That will focus Safari and cycle through its active windows. If Safari is not open, it will be opened on the first time, so this works also like the normal Safari icon.

To complete things you need to edit the script's properties - right click the script app in Finder and select Show Package Contents, then open Info.plist in Contents.

  • You need to add the LSBackgroundOnly (Application is background only) key with Checked value (as without that key the cycling doesn't work properly and the icon will just toggle two of the most recent window).
  • To get the authentic Safari icon you can copy/paste compass.icns from Safari.app's Contents | Resources to the corresponding place of the new script's. After that change Icon file property to point to the new icon.
  • After changes save the propertylist file.
  • It may be necessary to resave the script as well.

Now you should have an icon in dock that looks like Safari's but with added window cycling with subsequent clicks - if you named the script as Safari, nobody should notice any difference with original.

share|improve this answer
1  
Except, of course, that when you click it, the real Safari is just going to pop up at the end of the dock anyway. –  NReilingh Aug 21 '10 at 16:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.