I am new to programming for Mac OS X Lion (10.7.3) using Xcode 4.2.1
I am wanting to get a list of all visible windows and then either hide or minimize them.
So far, I have this code:
NSArray *appList = [[NSWorkspace sharedWorkspace] runningApplications];
for (id app in appList) {
for (id theWindow in app) { //How do I get list of windows from the app??
if ([theWindow isVisible]) {
[theWindow orderOut:sender];
}
}
}
I know this does not work, but am kind of stumped at how get a list of windows for each app.
Thanks
EDIT: I found an app called ShowDesktop (see accepted answer below) which does what I want, which is emulate the Show Desktop feature on Windows PC.
EDIT: March 2015: Found a better solution for this: Better Touch Tool (it's free) has a "Hide All Windows" shortcut that works like Windows, where it actually minimizes and hides all open windows (unlike OSX default of just moving them off the screen). You can assign it to any keyboard combo or mouse movement... I have assigned it to "OPTION_KEY + Move_Mouse_Into_Lower_Left_Corner".
CFArrayRef listOfWindows = CGWindowListCopyWindowInfo(kCGWindowListExcludeDesktopElements | kCGWindowListOptionOnScreenOnly,kCGNullWindowID );