How can I make ⌘H send an app to the back of the ⌘Tab stack on Lion? [duplicate]

Till Mac OS X Snow Leopard, pressing +H while using an application did two things...

  1. The application hid itself from view.
  2. The application placed itself at the end of the + switcher.

The 2nd point was very useful, because when I hid an app, I knew I wasn't going to use it for some time. Sending it to the end of the switcher helped me focus on the apps I was using more.

However, in Lion, even though +H hides the app, it only moves it to the next position in the switcher. This is equivalent to +ing between 2 apps, except that the app is now also hidden from view. IMO, this breaks a fundamental feature of the switcher and the app-hiding concept. I have no idea why this was done.

Does anyone have clues on how, if at all, this could be fixed? Or maybe places I should start looking? I just hope there's a preference buried in some plist file somewhere...


Solution 1:

This is a great question. This might be intended behavior rather than a bug. Mission Control seems to have blended both the old Expose and the old Spaces. With that in mind, launching a new app Full Screen places it on its own desktop. When you get to Mission Control you see it placed to the right of the original, empty Desktop. Open a second app Full Screen and that will place it again on its own desktop, next to the first Full Screen app you opened.

Just like the Home Screens in iOS and the old Spaces, it would seem that Apple intends these desktops to stay, space-wise, in the same place. Mail is "to the left" of Safari if I opened Safari after opening Mail. I agree that this spatial notion collides with our pre-conceived understanding of the switcher. That is same reason why hiding is disabled for Full Screen apps (pressing +H will not hide a Full Screen app).

If everything is full screen, the concept of hiding becomes less relevant. I think back to the older versions of Mac OS, where you had stacks upon stacks of windows. Hiding an app like Adobe Photoshop (and all of its many opened child windows for each one of my many opened images) made sense. If such window "stacking" is spatially not there (because those Full Screen apps are now side-by-side, they're not really stacked) then it almost makes sense that it doesn't work.

Having said all of that, I could not agree more that Lion has completely messed around with the workflow of many old-time Mac users. I do not necessarily agree with Apple's decisions here, I am just trying to play advocate and see if this one in particular has some explanation that makes sense. Hope this helps.

Update: This article at TidBITS mentions a new feature in Lion called Automatic Termination. I was not aware of this feature. I wonder if the behavior that is being experienced by this question's author is related to this.

Solution 2:

As this has been bugging me ever since this was changed I've given it another go. It seems the only working way so far is to imitate it by switching to all open apps before hiding. Not sure if applescript changed a bit but I had to change willlma's script like this for it to work. This also has substantially less key presses so should do the job faster.

delay 0.5
set i to 0
tell application "System Events"
    set first_app to name of the first process whose frontmost is true
    repeat with p in every process
        if visible of p then
            set i to i + 1
        end if
    end repeat
    repeat i - 1 times
        key down command
        key down shift
        keystroke tab
        delay 0.01
        key up shift
        key up command
        delay 0.1
    end repeat
    set visible of process first_app to false
end tell

It will show some flickering while switching and the delay can be too short if some animations take longer (like switching to full-screen apps), so the numbers are probably not optimal for all Macs or situations. And while it should be possible to set an Automator Service with a global hotkey, nothing happened for me. I've had more luck with the little application iCanHazShortcut where you can call osascript <scriptname> when pressing cmd-h.