{"id":278,"date":"2009-03-13T01:33:13","date_gmt":"2009-03-13T06:33:13","guid":{"rendered":"http:\/\/vgable.com\/blog\/2009\/03\/13\/always-showing-a-window-on-application-switch\/"},"modified":"2009-03-13T01:33:16","modified_gmt":"2009-03-13T06:33:16","slug":"always-showing-a-window-on-application-switch","status":"publish","type":"post","link":"https:\/\/vgable.com\/blog\/2009\/03\/13\/always-showing-a-window-on-application-switch\/","title":{"rendered":"(Always) Showing a Window on Application Switch"},"content":{"rendered":"<p><a href=\"http:\/\/www.uiandus.com\/\">Keith Lang<\/a> <a href=\"http:\/\/twitter.com\/songcarver\/status\/1320025981\">said<\/a> all Mac applications should show a window when you switch to them via command-tab or gestures.  I agree. I do think it is best to show <em>nothing<\/em> when the last window is closed; otherwise closing a window might mean more stuff in your face, not less.  But when context-switching back into an application I can&#8217;t think of a good reason why applications shouldn&#8217;t have something up that you can interact with <em>right now<\/em>.<sup>1<\/sup><\/p>\n<p>This is the behavior you get when switching between applications by clicking their icons in the dock.  It&#8217;s unfortunate that you have to do more work for your application to behave consistently no matter how it&#8217;s switched-to. Here&#8217;s how I&#8217;ve done this in <a href=\"http:\/\/vgable.com\/software\/index.html#IMLocation\">IMLocation<\/a>,<\/p>\n<p>In my <code><a href=\"http:\/\/www.cocoadev.com\/index.pl?NSApplication\">NSApplication<\/code> delegate<\/a> I implemented <code><a href=\"http:\/\/developer.apple.com\/documentation\/Cocoa\/Reference\/ApplicationKit\/Classes\/NSApplication_Class\/Reference\/Reference.html#\/\/apple_ref\/doc\/uid\/20000012-BBCBFBED\">- (void)applicationDidBecomeActive:(NSNotification *)aNotification<\/a><\/code> to check if no windows were visible, and if so, put something up. Here&#8217;s the exact code I use, replace <code>editCurrentLocation:<\/code> with what&#8217;s right for you:<\/p>\n<pre>\n- (void)applicationDidBecomeActive:(NSNotification *)aNotification\n{\n\t[self displayLocationWindowIfNoWindowIsOpen];\n}\n- (void) displayLocationWindowIfNoWindowIsOpen\n{\n\tNSArray *visibleWindows = [[NSApp windows] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@\"isVisible == YES\"]];\n\tif(<a href=\"http:\/\/vgable.com\/blog\/2008\/12\/16\/isempty\/\">IsEmpty<\/a>(visibleWindows))\n\t\t[self editCurrentLocation:nil];\n}\n<\/pre>\n<p><small><br \/>\n<sup>1<\/sup>Xcode, doesn&#8217;t put up anything when you click on it&#8217;s icon <em>and<\/em> you have turned off the <a href=\"http:\/\/macresearch.org\/xcode-and-interface-builder-3-brief-overview\">&#8220;Getting Started&#8221; splash screen<\/a>. This makes a bit of sense, because Xcode is a <em>project<\/em> editor, not a <em>document<\/em> editor. Projects are collections of many files, and having an &#8220;<a href=\"http:\/\/daringfireball.net\/linked\/2005\/07\/11\/untitled\">u<\/a>ntitled&#8221; default one does not make sense. But by default Xcode shows a window, the splash screen.  And there is an argument that it should show an empty file, like an Emacs &#8220;scratch buffer&#8221;.<br \/>\n<\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Keith Lang said all Mac applications should show a window when you switch to them via command-tab or gestures. I agree. I do think it is best to show nothing when the last window is closed; otherwise closing a window might mean more stuff in your face, not less. But when context-switching back into an [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,3,5,4],"tags":[279,212,134],"class_list":["post-278","post","type-post","status-publish","format-standard","hentry","category-cocoa","category-macosx","category-objective-c","category-programming","tag-mac-os-x","tag-nsapplication","tag-xcode"],"_links":{"self":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/278","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/comments?post=278"}],"version-history":[{"count":0,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/278\/revisions"}],"wp:attachment":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/media?parent=278"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/categories?post=278"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/tags?post=278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}