{"id":2653,"date":"2011-08-28T13:27:00","date_gmt":"2011-08-28T20:27:00","guid":{"rendered":"https:\/\/www.inmff.net\/peidm\/?p=2653"},"modified":"2011-08-28T22:34:20","modified_gmt":"2011-08-29T05:34:20","slug":"fixing-safari-and-spaces","status":"publish","type":"post","link":"https:\/\/www.inmff.net\/peidm\/2011\/08\/28\/fixing-safari-and-spaces\/","title":{"rendered":"Fixing Safari and Spaces"},"content":{"rendered":"<p>For those of you who are used to my usual musings on society, politics, and just general stuff, you&#8217;ll can safely skip this entry. This is a completely geeky blog entry, that applies pretty specifically to OS X Lion.<\/p>\n<hr \/>\n<p>So I don&#8217;t talk about programming\/scripting much, since well I don&#8217;t do much of it, and what I do is usually so specific to my needs, it doesn&#8217;t make sense to share it with the world. In this instance however, I think this&#8217;ll have a fairly common application.<\/p>\n<p>I&#8217;ve actually started using spaces, or as they call it now Mission Control in OS X. I&#8217;ve previously fiddled with it, but I&#8217;ve never really put it into standard use in my daily work. However, with Lion and its iOS like gestures, I have finally started using it. What I&#8217;ve done is put each of my basic organizational tools in its own space, so its easy to four finger swipe to it. My standard setup has five spaces:<\/p>\n<ul>\n<li>Dashboard &mdash; Which I like in its own space after initially being really annoyed with that setup.<\/li>\n<li>My main workspace &mdash; I do most of my web browsing, email, chatting, etc from this space<\/li>\n<li>Safari, opened to <a href=\"http:\/\/www.toodledo.com\/\">Toodledo<\/a> &mdash; I organize all my tasks and a bunch of other things in this great web application.<\/li>\n<li>iCal &mdash; I really like this calendaring application. It works quite well for my needs, and Apple hasn&#8217;t screwed it up in Lion.<\/li>\n<li>Safari, opened to <a href=\"http:\/\/www.me.com\">Mobile Me<\/a>&#8216;s Contacts Page &mdash; If I need to find someone&#8217;s address or phone number this is where I do it, since Apple completely screwed up the address book in Lion.<\/li>\n<\/ul>\n<hr \/>\n<p>So this serves me pretty well, except when:<\/p>\n<ol>\n<li>I&#8217;m interacting with another application in my main workspace.<\/li>\n<li>I open a link from that application.<\/li>\n<li>And, I don&#8217;t have a non-minimized window of Safari open in my main space.<\/li>\n<\/ol>\n<p>What I&#8217;d like to have happen would be for Safari to open a new window in my main workspace. However, Safari has different ideas, and opens a tab in one of my other spaces with Safari in it, and switches to it. (usually the Toodledo one, although I&#8217;m not quite sure how it makes its choice.) Usually, I try not to write any code\/scripts, I start with Googling around and see if I can find something that fits my needs.  <\/p>\n<p>So, as per my SOP, I went Googling and found a good script by <a href=\"http:\/\/hints.macworld.com\/users.php?mode=profile&amp;uid=14806\">jaysoffian<\/a> over at <a href=\"http:\/\/hints.macworld.com\/article.php?story=20091013114424722\">MacWorld<\/a>. Its from the Snow Leopard days, and actually using it has a few quirks that may be Lion specific. It does a great job if there are no instances of Safari in the main workspace, but if there is a minimized window, it believes this is sufficient to open the page in the current space, however Safari opens a tab in one of the other Spaces with Safari in it. So, more Googling for me!  I found a script by <a href=\"http:\/\/macscripter.net\/profile.php?id=33411\">relishgargler<\/a> over at <a href=\"http:\/\/macscripter.net\/viewtopic.php?id=35481\">MacScripter<\/a> which determines if a minimized window of the application exists. Since, I only have one space where Safari could be minimized, this works for me.<\/p>\n<p>The final quirk that I came upon was an edge case, that probably qualifies as a bug. If your last interaction with Safari was while it was full screen, it opens the link in a window, but the title and close, minimize, resize, and full size buttons are obscured below the menu bar. I did some fiddling that&#8217;ll fix that, however, I wasn&#8217;t able to find a way to see if this condition existed, so I just put the fix in for it every time that it could occur, which means that the window will do a little dance frequently.  It isn&#8217;t ideal, but it works. <\/p>\n<p>So I&#8217;ve put the script below as its source. Simply copy and paste, save as an application with the Stay Open option chosen. For those of you who don&#8217;t want to muck with AppleScript editor, you can get <a href=\"https:\/\/www.inmff.net\/peidm\/wp-content\/uploads\/SafariURLHelper3.zip\">SafariURLHelper3<\/a> from, uh that link. Simply unzip it and drop it somewhere nice on your Mac, I suggest putting it in the utilities folder.<\/p>\n<p>Finally, to make it actually work, go to Safari-&gt;Preferences-&gt;General, choose select, then find SafariURLHelper3 on your system. And you&#8217;re done.<\/p>\n<pre>\n-- SafariURLHelper3, heavily modified from http:\/\/hints.macworld.com\/article.php?story=20091013114424722 \n\n\non open location theURL\n\t--- Figures out what application is currently in front, given one method of opening a window needs to make Safari Frontmost.\n\tset CurFront to GetFrontmostApp()\n\t\n\t--Identifies if there are any windows of safari in this space, if not it creates a new window\t\n\ttell application \"System Events\"\n\t\tif (count of windows of process \"Safari\") = 0 then\n\t\t\ttell application \"Safari\" to make new document\n\t\t\tmy FixPositioning(CurFront)\n\t\t\ttell application \"Safari\" to open location theURL\n\t\t\treturn\n\t\tend if\n\tend tell\n\t\n\t-- Identifies if there are any minimized windows of Safari.  Might not work properly if you have it minimized in other spaces.  YMMV.\n\tset MinCheck to 0\n\ttell application \"Safari\"\n\t\trepeat with i in every window\n\t\t\ttell i\n\t\t\t\tif miniaturized is true then\n\t\t\t\t\tset MinCheck to 1\n\t\t\t\t\texit repeat\n\t\t\t\tend if\n\t\t\tend tell\n\t\tend repeat\n\tend tell\n\t\n\tif MinCheck is not equal to 0 then\n\t\ttell application \"Safari\" to make new document\n\t\tmy FixPositioning(CurFront)\n\t\ttell application \"Safari\" to open location theURL\n\t\treturn\n\tend if\n\t\n\t-- If we've not opened the URL above, just hand it off to Safari to open it.\n\t\n\ttell application \"Safari\" to open location theURL\n\t\nend open location\n\n-- From http:\/\/hintsforums.macworld.com\/archive\/index.php\/t-22098.html\n\n\non GetFrontmostApp()\n\trepeat\n\t\ttell application \"System Events\"\n\t\t\ttry\n\t\t\t\tset apName to name of first process whose frontmost is true\n\t\t\ton error --because Finder 7.5.1 doesn't list itself...\n\t\t\t\tif frontmost then\n\t\t\t\t\tset apName to \"Finder\"\n\t\t\t\telse --just to be on the safe side!\n\t\t\t\t\tset apName to \"\"\n\t\t\t\tend if\n\t\t\tend try\n\t\t\tif apName \u2260 \"\" then exit repeat\n\t\tend tell\n\tend repeat\n\treturn apName\nend GetFrontmostApp\n\non FixPositioning(CurFront)\n\t-- Ensures an edge case doesn't cause issues. If you've interacted with Safari full screen in a space it mispositions the window cutting off the title, and Close\/Minimize\/Resize buttons  \n\ttell application \"System Events\"\n\t\ttell process \"Safari\" to set frontmost to true\n\t\ttell process \"Safari\" to click menu item \"Zoom\" of menu \"Window\" of menu bar 1\n\t\ttell application \"Safari\" to set the bounds of the first window to {140, 0, 1160, 775}\n\t\ttell process CurFront to set frontmost to true\n\tend tell\n\treturn\nend FixPositioning\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>For those of you who are used to my usual musings on society, politics, and just general stuff, you&#8217;ll can safely skip this entry. This is a completely geeky blog entry, that applies pretty specifically to OS X Lion. So I don&#8217;t talk about programming\/scripting much, since well I don&#8217;t do much of it, and [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[24,25,26],"class_list":["post-2653","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-applescript","tag-os-x","tag-safari"],"_links":{"self":[{"href":"https:\/\/www.inmff.net\/peidm\/wp-json\/wp\/v2\/posts\/2653","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inmff.net\/peidm\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inmff.net\/peidm\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inmff.net\/peidm\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inmff.net\/peidm\/wp-json\/wp\/v2\/comments?post=2653"}],"version-history":[{"count":5,"href":"https:\/\/www.inmff.net\/peidm\/wp-json\/wp\/v2\/posts\/2653\/revisions"}],"predecessor-version":[{"id":2658,"href":"https:\/\/www.inmff.net\/peidm\/wp-json\/wp\/v2\/posts\/2653\/revisions\/2658"}],"wp:attachment":[{"href":"https:\/\/www.inmff.net\/peidm\/wp-json\/wp\/v2\/media?parent=2653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inmff.net\/peidm\/wp-json\/wp\/v2\/categories?post=2653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inmff.net\/peidm\/wp-json\/wp\/v2\/tags?post=2653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}