<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>blog@insidesystems.net: Category OS X</title>
    <link>http://blog.insidesystems.net/articles/category/os-x</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>QS, AppleScript and moving windows</title>
      <description>&lt;p&gt;&lt;span class="caps"&gt;A 15&lt;/span&gt;&amp;#8221; laptop has a relatively small display, so I find myself routinely wanting to put a window all the way to one edge or the other, to help maximize the use of this.&lt;/p&gt;


	&lt;p&gt;I decided that this should be simple, something along the lines of ^⌥⌘&amp;larr; to slam a window to the left edge of my screen and so on.&lt;/p&gt;


	&lt;p&gt;There were a few hitches, but I did it as follows:&lt;/p&gt;&lt;p&gt;First I made some scripts:&lt;/p&gt;


move_left
&lt;pre&gt;
&lt;code&gt;
tell application "Finder" 
    set {disp_x1, disp_y1, disp_x2, disp_y2} to bounds of window of desktop
end tell

tell application "System Events" 
    set frontmostApplication to name of the first process whose frontmost is true

    tell process frontmostApplication
        tell window 1
            set {x1, y1} to position
            set position to {disp_x1, y1}
        end tell
    end tell
end tell
&lt;/code&gt;
&lt;/pre&gt;

move_right
&lt;pre&gt;
&lt;code&gt;
tell application "Finder" 
    set {disp_x1, disp_y1, disp_x2, disp_y2} to bounds of window of desktop
end tell

tell application "System Events" 
    set frontmostApplication to name of the first process whose frontmost is true

    tell process frontmostApplication
        tell window 1
            set {x1, y1} to position
            set {x_off, y_off} to size

            set position to {disp_x2 - x_off, y1}
        end tell
    end tell
end tell
&lt;/code&gt;
&lt;/pre&gt;

move up
&lt;pre&gt;&lt;code&gt;
tell application "Finder" 
    set {disp_x1, disp_y1, disp_x2, disp_y2} to bounds of window of desktop
end tell

tell application "System Events" 
    set frontmostApplication to name of the first process whose frontmost is true

    set disp_y1 to disp_y1 + 22

    tell process frontmostApplication
        tell window 1
            set {x1, y1} to position

            set position to {x1, disp_y1}
        end tell
    end tell
end tell
&lt;/code&gt;
&lt;/pre&gt;

move down
&lt;pre&gt;
&lt;code&gt;
tell application "Finder" 
    set {disp_x1, disp_y1, disp_x2, disp_y2} to bounds of window of desktop
end tell

tell application "System Events" 
    set frontmostApplication to name of the first process whose frontmost is true

    tell process frontmostApplication
        tell window 1
            set {x1, y1} to position
            set {x_off, y_off} to size

            set position to {x1, disp_y2 - y_off}
        end tell
    end tell
end tell
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;And at the suggestion of Alex L.&lt;/p&gt;


move center
&lt;pre&gt;
&lt;code&gt;
tell application "Finder" 
    set {disp_x1, disp_y1, disp_x2, disp_y2} to bounds of window of desktop
end tell

tell application "System Events" 
    set frontmostApplication to name of the first process whose frontmost is true

    set disp_y1 to disp_y1 + 22

    tell process frontmostApplication
        tell window 1
            set {x1, y1} to position
            set {x_off, y_off} to size

            set position to {disp_x1 + (disp_x2 - x_off) / 2, disp_y1 + (disp_y2 - y_off) / 2}
        end tell
    end tell
end tell
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;I added these to QS hotkeys, and  used the same technique to make windows do incremental moves as well.&lt;/p&gt;


	&lt;p&gt;Credit to the MacNN Forums, who helped me find a useful answer in &lt;a href="http://forums.macnn.com/79/developer-center/345599/moving-windows-with-qs-and-applescript/"&gt;this thread&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;Follow-up: Zachary Cohen wrote a correction: 
&lt;em&gt;Seems like a cool little article, but you need to make sure that Access for assistive devices is turned on. You do this by going to &amp;#8220;System Preferences&amp;#8221; then selecting the &amp;#8220;Universal Access&amp;#8221; from the options. Then click the click the checkbox at the bottom &amp;#8220;Enable access for assistive devices&amp;#8221; then these scripts should work. &lt;/em&gt;&lt;/p&gt;</description>
      <pubDate>Mon, 20 Aug 2007 02:53:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:7ddf7bb3-9e73-43bb-a292-6df566fbef07</guid>
      <author>Kevin Way</author>
      <link>http://blog.insidesystems.net/articles/2007/08/20/qs-applescript-and-moving-windows</link>
      <category>Off-Topic</category>
      <category>OS X</category>
    </item>
    <item>
      <title>Growl, Mail.app and AppleScript</title>
      <description>&lt;p&gt;I wanted a simple system that would notify me whenever I received an e-mail from somebody &amp;#8220;important&amp;#8221;, but not for every new message that hit my inbox.&lt;/p&gt;


	&lt;p&gt;I tried GrowlMail and Mail.Appetizer, but found them both unsatisfactory.  I finally decided that what I really wanted was a growl message to appear for messages from selected recipients.  Something with the name and the subject of the e-mail, like this:&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://blog.insidesystems.net/files/growl.png"&gt;&lt;/p&gt;


	&lt;p&gt;Fortunately, it turned out to be reasonably simple.&lt;/p&gt;&lt;p&gt;First, I opened up Address Book, and made sure that the important people were all listed in appropriate groups and correct e-mail addresses.&lt;/p&gt;


	&lt;p&gt;Having done that, I opened Mail.app, and added a rule:&lt;/p&gt;


&lt;blockquote&gt;
Description: Growl&lt;br/&gt;
&lt;br/&gt;
If any of the following conditions are met:&lt;br/&gt;
Sender is member of Group: Clients&lt;br/&gt;
Sender is member of Group: Family&lt;br/&gt;
Sender is member of Group: InsideSystems&lt;br/&gt;
&lt;br/&gt;
Perform the following actions:&lt;br/&gt;
Run AppleScript: ~/Library/Scripts/Applications/Mail/MailScript.scpt&lt;br/&gt;
&lt;/blockquote&gt;

but ho, you say, that script does not exist!  Never fear, then I loaded up Script Editor and created MailScript.scpt as follows:
&lt;pre&gt;
&lt;code&gt;
on perform_mail_action(info)

    tell application "Mail" 

        set selectedMessages to |SelectedMessages| of info
        set theRule to |Rule| of info

        repeat with eachMessage in selectedMessages
            set theSubject to subject of eachMessage
            set theSender to sender of eachMessage

            tell application "GrowlHelperApp" 

                set the allNotificationsList to ¬
                    {"New Mail"}

                set the enabledNotificationsList to ¬
                    {"New Mail"}

                register as application ¬
                    "MailScript" all notifications allNotificationsList ¬
                    default notifications enabledNotificationsList ¬
                    icon of application "Mail" 

                notify with name ¬
                    "New Mail" title ¬
                    "New Mail from " &amp;#38; theSender description ¬
                    theSubject application name "MailScript" 

            end tell

        end repeat
    end tell
end perform_mail_action
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Now, this was the first time I ever did anything in AppleScript, so it&amp;#8217;s quite possible there is a much better way to do all of this.  As it stands, I simply glued together some sample code from Growl and some sample code from &lt;a href="http://www.macosxhints.com/article.php?story=20030116071118239"&gt;this hint&lt;/a&gt; on the excellent &lt;a href="http://www.macosxhints.com"&gt;MacOSXHints.com&lt;/a&gt;, and it appears to work as desired.&lt;/p&gt;


	&lt;p&gt;Finally, I went into the growl prefpane, and set the priority and stickiness, so that these messages would stay on my screen even if I happened to be otherwise occupied when they came in.&lt;/p&gt;


	&lt;p&gt;Voila!  Nothing spectacularly complex, but it&amp;#8217;s a nice example of what I like about Apple.  Everything&amp;#8217;s easy to use out of the box, but when I dreamed up a random feature, I was able to implement it in a short period of time, despite having never even used their glue language before.&lt;/p&gt;


	&lt;p&gt;Hopefully somebody else would like this feature too!&lt;/p&gt;</description>
      <pubDate>Fri, 17 Aug 2007 14:55:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:74a15967-64c7-433a-a416-8f1c880d31be</guid>
      <author>Kevin Way</author>
      <link>http://blog.insidesystems.net/articles/2007/08/17/growl-mail-app-and-applescript</link>
      <category>E-Mail</category>
      <category>Off-Topic</category>
      <category>OS X</category>
    </item>
  </channel>
</rss>
