<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.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: QS, AppleScript and moving windows</title>
    <link>http://blog.insidesystems.net/articles/2007/08/20/qs-applescript-and-moving-windows</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>
  </channel>
</rss>
