<?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>The Blog of Maxim Porges &#187; AppleScript</title>
	<atom:link href="http://www.maximporges.com/tag/applescript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.maximporges.com</link>
	<description>Winning At Yelling</description>
	<lastBuildDate>Sat, 08 Oct 2011 19:33:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>An AppleScript to Toggle Sleep Modes</title>
		<link>http://www.maximporges.com/2011/01/23/an-applescript-to-toggle-sleep-modes/</link>
		<comments>http://www.maximporges.com/2011/01/23/an-applescript-to-toggle-sleep-modes/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 16:55:57 +0000</pubDate>
		<dc:creator>Maxim Porges</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AppleScript]]></category>

		<guid isPermaLink="false">http://www.maximporges.com/?p=915</guid>
		<description><![CDATA[I have a 2008 unibody MacBook Pro, and the battery is starting to show its age. When I leave it in sleep mode, I maybe get a day and a half before the battery is completely drained. Putting my laptop into hibernation keeps the battery charge longer, but takes longer to start up as well. [...]]]></description>
			<content:encoded><![CDATA[<p>I have a 2008 unibody MacBook Pro, and the battery is starting to show its age. When I leave it in sleep mode, I maybe get a day and a half before the battery is completely drained. Putting my laptop into hibernation keeps the battery charge longer, but takes longer to start up as well. Depending on what I&#8217;m doing with my laptop (i.e. putting it to sleep at home for a few hours vs. traveling with it) I like to change the power mode accordingly so that I can go longer without having to plug it in.</p>
<p>You can change the power-down mode from sleep to hibernate and vice versa using the <i>pmset</i> command line utility, but I kept forgetting the options to pass in, so I wrote a little AppleScript that does it for me. The script prompts you for your admin password, checks the current sleep mode, and gives you the option to toggle the other mode if you want to.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">set</span> loggedInUser <span style="color: #ff0033; font-weight: bold;">to</span> system attribute <span style="color: #009900;">&quot;USER&quot;</span>
<span style="color: #ff0033; font-weight: bold;">set</span> userCancelled <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">false</span>
<span style="color: #ff0033; font-weight: bold;">try</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> sudoPasswordResult <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">display dialog</span> <span style="color: #009900;">&quot;Please enter your password: &quot;</span> <span style="color: #0066ff;">default answer</span> <span style="color: #009900;">&quot;&quot;</span> <span style="color: #ff0033; font-weight: bold;">with</span> title <span style="color: #009900;">&quot;Password&quot;</span> <span style="color: #ff0033; font-weight: bold;">with</span> icon caution <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #0066ff;">hidden</span> answer
<span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #ff0033; font-weight: bold;">error</span> <span style="color: #0066ff;">number</span> <span style="color: #000000;">-</span><span style="color: #000000;">128</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> userCancelled <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">true</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #ff0033;">not</span> userCancelled <span style="color: #ff0033; font-weight: bold;">then</span>
	<span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #0066ff;">text</span> returned <span style="color: #ff0033; font-weight: bold;">of</span> sudoPasswordResult <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">not</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
		<span style="color: #ff0033; font-weight: bold;">set</span> sudoPassword <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">text</span> returned <span style="color: #ff0033; font-weight: bold;">of</span> sudoPasswordResult
		<span style="color: #ff0033; font-weight: bold;">set</span> currentModeText <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;pmset -g | grep hibernatemode&quot;</span> user <span style="color: #0066ff;">name</span> loggedInUser password sudoPassword <span style="color: #ff0033; font-weight: bold;">with</span> administrator privileges
		<span style="color: #ff0033; font-weight: bold;">set</span> currentMode <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">item</span> <span style="color: #000000;">16</span> <span style="color: #ff0033; font-weight: bold;">of</span> currentModeText
&nbsp;
		<span style="color: #ff0033; font-weight: bold;">set</span> selectedButton <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">1</span>
		<span style="color: #ff0033; font-weight: bold;">set</span> currentSleepModeName <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span>
		<span style="color: #ff0033; font-weight: bold;">if</span> currentMode <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;1&quot;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
			#Hibernate mode <span style="color: #000000;">-</span> default <span style="color: #0066ff;">selection</span> toggles <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">Sleep</span>
			<span style="color: #ff0033; font-weight: bold;">set</span> selectedButton <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">1</span>
			<span style="color: #ff0033; font-weight: bold;">set</span> currentSleepModeName <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;Hibernate&quot;</span>
		<span style="color: #ff0033; font-weight: bold;">else</span> <span style="color: #ff0033; font-weight: bold;">if</span> currentMode <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;3&quot;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
			#Sleep mode <span style="color: #000000;">-</span> default <span style="color: #0066ff;">selection</span> toggles <span style="color: #ff0033; font-weight: bold;">to</span> Hibernate
			<span style="color: #ff0033; font-weight: bold;">set</span> currentSleepModeName <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;Sleep&quot;</span>
			<span style="color: #ff0033; font-weight: bold;">set</span> selectedButton <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">2</span>
		<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
&nbsp;
		<span style="color: #ff0033; font-weight: bold;">set</span> sleepModeResults <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">display dialog</span> <span style="color: #009900;">&quot;Current sleep mode is &quot;</span> <span style="color: #000000;">&amp;</span> currentSleepModeName <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;. Select new sleep mode.&quot;</span> <span style="color: #ff0033; font-weight: bold;">with</span> title <span style="color: #009900;">&quot;Select new sleep mode&quot;</span> <span style="color: #0066ff;">buttons</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;Sleep&quot;</span>, <span style="color: #009900;">&quot;Hibernate&quot;</span><span style="color: #000000;">&#125;</span> default button selectedButton
		<span style="color: #ff0033; font-weight: bold;">set</span> newSleepMode <span style="color: #ff0033; font-weight: bold;">to</span> button returned <span style="color: #ff0033; font-weight: bold;">of</span> sleepModeResults
		<span style="color: #ff0033; font-weight: bold;">if</span> newSleepMode <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #009900;">&quot;Sleep&quot;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
			<span style="color: #ff0033; font-weight: bold;">set</span> sleepModeFlag <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">3</span>
		<span style="color: #ff0033; font-weight: bold;">else</span> <span style="color: #ff0033; font-weight: bold;">if</span> newSleepMode <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #009900;">&quot;Hibernate&quot;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
			<span style="color: #ff0033; font-weight: bold;">set</span> sleepModeFlag <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">1</span>
		<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
&nbsp;
		<span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;pmset -a hibernatemode &quot;</span> <span style="color: #000000;">&amp;</span> sleepModeFlag user <span style="color: #0066ff;">name</span> loggedInUser password sudoPassword <span style="color: #ff0033; font-weight: bold;">with</span> administrator privileges
	<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.maximporges.com/2011/01/23/an-applescript-to-toggle-sleep-modes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using AppleScript to Position iChat Windows</title>
		<link>http://www.maximporges.com/2010/01/25/using-applescript-to-position-ichat-windows/</link>
		<comments>http://www.maximporges.com/2010/01/25/using-applescript-to-position-ichat-windows/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 02:30:36 +0000</pubDate>
		<dc:creator>Maxim Porges</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AppleScript]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.maximporges.com/?p=574</guid>
		<description><![CDATA[We use instant messaging quite a bit at Highwinds. I bounce back and forth between using my laptop by itself, and using it with a secondary 22&#8243; display. Regardless of how I&#8217;m using my laptop, I like my iChat windows to fill the laptop screen with about a 3-pixel gap between each of them. This [...]]]></description>
			<content:encoded><![CDATA[<p>We use instant messaging quite a bit at Highwinds. I bounce back and forth between using my laptop by itself, and using it with a secondary 22&#8243; display. Regardless of how I&#8217;m using my laptop, I like my iChat windows to fill the laptop screen with about a 3-pixel gap between each of them. This means that when I&#8217;m on my laptop alone, its screen gets filled when I Apple-Tab to iChat, and when I&#8217;m on a two-monitor setup, the larger attached monitor display is free of chat windows and they are all present on my laptop screen so I can work while watching for chats. </p>
<p>My AIM and GMail buddy lists are about the same length, so I like to stack them on top of each other with half of the screen height given to each. My Highwinds buddy list is the longest, so that gets a full column to itself to the right of my AIM/GMail lists. Finally, I have my chat window occupying the rest of the right-hand side of the display. You can see this in the image below (some screen names have been obscured to protect the innocent).</p>
<p><a href="http://www.maximporges.com/files/ichat_layout.png"><img src="http://www.maximporges.com/files/ichat_layout.png" alt="My iChat Layout" width="525" /></a></p>
<p>Unfortunately, Apple hasn&#8217;t programmed OS X to remember the position of windows between laptop-only and display-attached configurations, which means I always have to manually move my chat windows back to the second display after I reconnect it to my laptop. This is a pain in the ass. I finally got a few minutes to write an AppleScript to do this for me automatically, presented below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- Get display area</span>
<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Finder&quot;</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> displayAreaDimensions <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">bounds</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">window</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">desktop</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> widthOfDisplayArea <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">item</span> <span style="color: #000000;">3</span> <span style="color: #ff0033; font-weight: bold;">of</span> displayAreaDimensions
	<span style="color: #ff0033; font-weight: bold;">set</span> heightOfDisplayArea <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">item</span> <span style="color: #000000;">4</span> <span style="color: #ff0033; font-weight: bold;">of</span> displayAreaDimensions
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;System Events&quot;</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033; font-weight: bold;">tell</span> process <span style="color: #009900;">&quot;Dock&quot;</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> dockDimensions <span style="color: #ff0033; font-weight: bold;">to</span> size <span style="color: #ff0033; font-weight: bold;">in</span> <span style="color: #0066ff;">list</span> <span style="color: #000000;">1</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> heightOfDock <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">item</span> <span style="color: #000000;">2</span> <span style="color: #ff0033; font-weight: bold;">of</span> dockDimensions
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Set up desired coordinates when running iChat on the laptop monitor at 1440x900</span>
<span style="color: #ff0033; font-weight: bold;">set</span> maximumChatWindowHeight <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>heightOfDisplayArea <span style="color: #000000;">-</span> heightOfDock<span style="color: #000000;">&#41;</span>
<span style="color: #ff0033; font-weight: bold;">set</span> chatWindowWidth <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">275</span>
<span style="color: #ff0033; font-weight: bold;">set</span> padding <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">3</span>
<span style="color: #ff0033; font-weight: bold;">set</span> heightOfMenuBar <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">22</span>
<span style="color: #ff0033; font-weight: bold;">set</span> laptopPhysicalDisplayWidth <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">1440</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">set</span> aimCoordinates <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#91;</span><span style="color: #000000;">0</span>, <span style="color: #000000;">0</span>, chatWindowWidth, <span style="color: #000000;">&#40;</span>maximumChatWindowHeight <span style="color: #000000;">/</span> <span style="color: #000000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">-</span> heightOfMenuBar<span style="color: #000000;">&#93;</span>
<span style="color: #ff0033; font-weight: bold;">set</span> gmailCoordinates <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#91;</span><span style="color: #000000;">0</span>, <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">item</span> <span style="color: #000000;">4</span> <span style="color: #ff0033; font-weight: bold;">of</span> aimCoordinates<span style="color: #000000;">&#41;</span> <span style="color: #000000;">+</span> <span style="color: #000000;">&#40;</span>heightOfMenuBar <span style="color: #000000;">+</span> padding<span style="color: #000000;">&#41;</span>, chatWindowWidth, maximumChatWindowHeight<span style="color: #000000;">&#93;</span>
<span style="color: #ff0033; font-weight: bold;">set</span> highwindsCoordinates <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#91;</span>chatWindowWidth <span style="color: #000000;">+</span> padding, <span style="color: #000000;">0</span>, <span style="color: #000000;">&#40;</span>chatWindowWidth <span style="color: #000000;">*</span> <span style="color: #000000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">+</span> padding, maximumChatWindowHeight<span style="color: #000000;">&#93;</span>
<span style="color: #ff0033; font-weight: bold;">set</span> chatWindowCoordinates <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#40;</span>chatWindowWidth <span style="color: #000000;">*</span> <span style="color: #000000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">+</span> <span style="color: #000000;">&#40;</span>padding <span style="color: #000000;">*</span> <span style="color: #000000;">2</span><span style="color: #000000;">&#41;</span>, <span style="color: #000000;">0</span>, laptopPhysicalDisplayWidth, maximumChatWindowHeight<span style="color: #000000;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Shift everything over by laptop display width if using a second monitor</span>
<span style="color: #ff0033; font-weight: bold;">if</span> widthOfDisplayArea <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">greater</span> than laptopPhysicalDisplayWidth <span style="color: #ff0033; font-weight: bold;">then</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> widthOfSecondaryDisplay <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>widthOfDisplayArea <span style="color: #000000;">-</span> laptopPhysicalDisplayWidth<span style="color: #000000;">&#41;</span>
	<span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> currentDimensions <span style="color: #ff0033; font-weight: bold;">in</span> <span style="color: #000000;">&#91;</span>aimCoordinates, gmailCoordinates, highwindsCoordinates, chatWindowCoordinates<span style="color: #000000;">&#93;</span>
		<span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> itemPosition <span style="color: #ff0033; font-weight: bold;">in</span> <span style="color: #000000;">&#91;</span><span style="color: #000000;">1</span>, <span style="color: #000000;">3</span><span style="color: #000000;">&#93;</span>
			<span style="color: #ff0033; font-weight: bold;">set</span> <span style="color: #0066ff;">item</span> itemPosition <span style="color: #ff0033; font-weight: bold;">of</span> currentDimensions <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #0066ff;">item</span> itemPosition <span style="color: #ff0033; font-weight: bold;">of</span> currentDimensions<span style="color: #000000;">&#41;</span> <span style="color: #000000;">+</span> widthOfSecondaryDisplay<span style="color: #000000;">&#41;</span>
		<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
	<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Position chat windows</span>
<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;iChat&quot;</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> <span style="color: #0066ff;">bounds</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">window</span> <span style="color: #009900;">&quot;AIM Buddy List&quot;</span> <span style="color: #ff0033; font-weight: bold;">to</span> aimCoordinates
	<span style="color: #ff0033; font-weight: bold;">set</span> <span style="color: #0066ff;">bounds</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">window</span> <span style="color: #009900;">&quot;myGoogleTalkAddress@gmail.com&quot;</span> <span style="color: #ff0033; font-weight: bold;">to</span> gmailCoordinates
	<span style="color: #ff0033; font-weight: bold;">set</span> <span style="color: #0066ff;">bounds</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">window</span> <span style="color: #009900;">&quot;myWorkEmailAddress@highwinds.com&quot;</span> <span style="color: #ff0033; font-weight: bold;">to</span> highwindsCoordinates
	<span style="color: #ff0033; font-weight: bold;">set</span> <span style="color: #0066ff;">bounds</span> <span style="color: #ff0033; font-weight: bold;">of</span> windows <span style="color: #ff0033;">whose</span> <span style="color: #0066ff;">name</span> <span style="color: #ff0033;">contains</span> <span style="color: #009900;">&quot;Chats&quot;</span> <span style="color: #ff0033; font-weight: bold;">to</span> chatWindowCoordinates
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span></pre></td></tr></table></div>

<p>The script is pretty simple. It grabs the screen and dock dimensions, and sets up some global variables. Then, for each of my buddy lists (AIM, GMail, and Highwinds) it sets up 4-coordinate position arrays describing the [top left x, top left y, bottom right x, bottom right y] coordinates that I want each window to end up in. Next, it checks the total display area: if the area is greater than the width of my physical laptop display, it bumps all the X coordinates over by the width of the secondary display so that the windows end up on my laptop display (since I position my laptop to the right of my secondary display). Finally, it tells iChat to position the windows, referencing each by their title bar. I group all my chats in to a single window, so the title of this window is something like &#8220;18 Chats&#8221;; as a result, I use a query-like expression to reference this window&#8217;s title.</p>
<p>Rather than dynamically setting the position of your chat windows, if you would prefer to move your chat windows to the positions that you want them in and have your Mac tell you what the coordinates are, you can use the script below. You can then hard-code these coordinates in to the coordinate arrays in the script above.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;iChat&quot;</span>
	<span style="color: #0066ff;">activate</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> allChatWindows <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">every</span> <span style="color: #0066ff;">window</span>
	<span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> currentWindow <span style="color: #ff0033; font-weight: bold;">in</span> allChatWindows
		<span style="color: #ff0033; font-weight: bold;">set</span> windowBounds <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">the</span> <span style="color: #0066ff;">bounds</span> <span style="color: #ff0033; font-weight: bold;">of</span> currentWindow
		<span style="color: #ff0033; font-weight: bold;">set</span> allBounds <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span>
		<span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> bound <span style="color: #ff0033; font-weight: bold;">in</span> windowBounds
			<span style="color: #ff0033; font-weight: bold;">set</span> allBounds <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>allBounds <span style="color: #000000;">&amp;</span> bound <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;,&quot;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
		<span style="color: #0066ff;">display dialog</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> currentWindow <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;: &quot;</span> <span style="color: #000000;">&amp;</span> allBounds<span style="color: #000000;">&#41;</span>
	<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.maximporges.com/2010/01/25/using-applescript-to-position-ichat-windows/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

