<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>incrementalism.net &#187; AppleScript</title>
	<atom:link href="http://incrementalism.net/tag/applescript/feed" rel="self" type="application/rss+xml" />
	<link>http://incrementalism.net</link>
	<description></description>
	<lastBuildDate>Tue, 30 Aug 2011 04:44:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<cloud domain='incrementalism.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Centering Windows in Mac OS X with AppleScript</title>
		<link>http://incrementalism.net/tech/centering-windows-in-mac-os-x-with-applescript</link>
		<comments>http://incrementalism.net/tech/centering-windows-in-mac-os-x-with-applescript#comments</comments>
		<pubDate>Mon, 20 Jul 2009 01:17:42 +0000</pubDate>
		<dc:creator>Tim Moore</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[AppleScript]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[obsession]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://incrementalism.net/?p=124</guid>
		<description><![CDATA[I can be a little OCD with the windows on my screen. I tend to line them up at the edges or try to center them in the display. Maybe it&#8217;s a bad habit, but it&#8217;s one I&#8217;m probably not going to shake any time soon, so the least I can do is try to [...]]]></description>
			<content:encoded><![CDATA[<p>I can be a little OCD with the windows on my screen.  I tend to line them up at the edges or try to center them in the display. Maybe it&#8217;s a bad habit, but it&#8217;s one I&#8217;m probably not going to shake any time soon, so the least I can do is try to avoid wasting too much time on it.</p>
<p><span id="more-124"></span></p>
<p>I found <a href="http://github.com/wycats/osx-window-sizing/blob/80973de9772cffce57621fc27a74b693701c35fa/center.applescript">an AppleScript on GitHub</a> for centering the frontmost window. It didn&#8217;t do quite what I wanted, so here&#8217;s my slightly-modified version, which will center the window in your screen horizontally without changing the vertical position or size.</p>
<pre class="brush: applescript; class-name: applescript; title: ; notranslate">
tell application &quot;Finder&quot;
	set screenSize to bounds of window of desktop
	set screenWidth to item 3 of screenSize
end tell

tell application &quot;System Events&quot;
	set myFrontMost to name of first item of ¬
		(processes whose frontmost is true)
end tell

try
	tell application myFrontMost
		set windowSize to bounds of window 1
		set windowXl to item 1 of windowSize
		set windowYt to item 2 of windowSize
		set windowXr to item 3 of windowSize
		set windowYb to item 4 of windowSize

		set windowWidth to windowXr - windowXl

		set bounds of window 1 to {¬
			(screenWidth - windowWidth) / 2.0, ¬
			windowYt, ¬
			(screenWidth + windowWidth) / 2.0, ¬
			windowYb}
	end tell
end try
</pre>
<p>Paste this into Script Editor or <a href='http://static.incrementalism.net/wp-content/uploads/2009/07/Center-Window.scpt'>download the script file</a>. Put the file in ~/Library/Scripts. Make sure you&#8217;ve got the Script menu turned on in the AppleScript Utility application. It will show up in there, and should work in most Mac applications.</p>
<p>I have found a couple of limitations. It doesn&#8217;t seem to work at all with Firefox, which doesn&#8217;t have very complete AppleScript support. It&#8217;s likely that there are other applications out there with missing or incomplete AppleScript support that this won&#8217;t work for either. The second problem is that there&#8217;s <a href="http://openradar.appspot.com/5765608">a bug in the Terminal application</a> that moves the window upwards, even though the script is written in a way that&#8217;s supposed to preserve the vertical position. It would be possible to work around this, but I decided that it didn&#8217;t bother me enough to clutter up the code. If you want a workaround, post a comment and I&#8217;ll give it a shot.</p>
<p>The original script doesn&#8217;t specify a license, so I hope it&#8217;s OK to modify and share it. I figure that, since it&#8217;s published on GitHub, and the author releases a lot of open source code under very liberal licenses, that he&#8217;s probably not intending to keep very tight control over it. My changes are offered to the public domain.</p>
<p>I&#8217;m just as obsessive with making sure objects are lined up straight on my (real life) desk top. Sadly, AppleScript can&#8217;t help me there.</p>
<p><strong>Update, 15-Nov-2010:</strong> This continues to be a fairly popular post, which a lot of people seem to come across through search engines. See the comments below for tips about ensuring that the window size doesn&#8217;t change, and for centering vertically as well. I&#8217;ve also noticed that this fails on multi-display setups, centering between the two screens instead of on the current screen. I&#8217;ll try to come up with a fix for that.</p>
]]></content:encoded>
			<wfw:commentRss>http://incrementalism.net/tech/centering-windows-in-mac-os-x-with-applescript/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 2/11 queries in 0.023 seconds using disk: basic
Object Caching 305/318 objects using disk: basic
Content Delivery Network via static.incrementalism.net

Served from: incrementalism.net @ 2012-05-29 06:45:14 -->
