<?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>Jeff Kelley’s Blog &#187; AppleScript</title>
	<atom:link href="http://blog.slaunchaman.com/tag/applescript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.slaunchaman.com</link>
	<description>Mac tips, iPhone applications, and the like</description>
	<lastBuildDate>Wed, 10 Mar 2010 02:28:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Automatically get the latest Chromium snapshot with launchd</title>
		<link>http://blog.slaunchaman.com/2009/05/19/automatically-get-the-latest-chromium-snapshot-with-launchd/</link>
		<comments>http://blog.slaunchaman.com/2009/05/19/automatically-get-the-latest-chromium-snapshot-with-launchd/#comments</comments>
		<pubDate>Wed, 20 May 2009 04:24:08 +0000</pubDate>
		<dc:creator>Jeff Kelley</dc:creator>
				<category><![CDATA[Miscellania]]></category>
		<category><![CDATA[AppleScript]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[Chromium]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[launchd]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[open-source]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://blog.slaunchaman.com/?p=183</guid>
		<description><![CDATA[I’ve been checking out the snapshots of Chromium recently, and they’re coming quicker than you can say “multithreaded web browser.” To facilitate always having the latest version, I wrote a quick LaunchAgent that takes care of it on Mac OS X. First, I have a script named ~/bin/chromiupdate:


#!/bin/bash

# Downloads the latest version of Chromium.

remove_working_dir()
{
  [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been checking out the <a href="http://build.chromium.org/buildbot/snapshots/sub-rel-mac">snapshots</a> of <a href="http://www.chromium.org">Chromium</a> recently, and they’re coming quicker than you can say “multithreaded web browser.” To facilitate always having the latest version, I wrote a quick LaunchAgent that takes care of it on Mac OS X. First, I have a script named <strong>~/bin/chromiupdate</strong>:<br />
<code><br />
<blockquote>
<pre>#!/bin/bash

# Downloads the latest version of Chromium.

remove_working_dir()
{
    rm -rf "${WORKING_DIR}"
    exit 0
}

USER_DIR=$(dscl . -read /Users/$(whoami) NFSHomeDirectory | awk '{ print $2 }')
USER_APP_DIR="${USER_DIR}/Applications"
CHROMIUM_DIR="${USER_APP_DIR}/Chromium.app"
LATEST_URL="http://build.chromium.org/buildbot/snapshots/sub-rel-mac/LATEST"
TMP_DIR="/private/tmp"
WORKING_DIR="${TMP_DIR}/.chromium_launchd"
URL_BEGIN="http://build.chromium.org/buildbot/snapshots/sub-rel-mac"

if [ ! -d "${CHROMIUM_DIR}" ]; then
    mkdir -p "${CHROMIUM_DIR}"
fi

INSTALLED_VERSION="$(defaults read "${CHROMIUM_DIR}/Contents/Info" SVNRevision)"
VERSION=$(curl "${LATEST_URL}")

if [ "${VERSION}" != "${INSTALLED_VERSION}" ]; then
    logger Installed Chromium version \(${INSTALLED_VERSION}\) does not equal \
            latest version \(${VERSION}\), updating now...
    mkdir "${WORKING_DIR}" || exit 1
    trap remove_working_dir 1 2 3 6 15
    cd "${WORKING_DIR}" || exit 1
    curl -O "${URL_BEGIN}/${VERSION}/chrome-mac.zip"
    unzip chrome-mac.zip
    rsync -HavP --exclude="Contents/MacOS/chrome_debug.log" \
          "${WORKING_DIR}/chrome-mac/Chromium.app/" "${CHROMIUM_DIR}/"

    if [ "$(ps -aef | grep -i chromium | grep -v grep)" != "" ]; then
        open "${USER_DIR}/Library/Scripts/Chromium Update Dialog.app"
    fi

    logger "Chromium update complete. Version ${VERSION} installed."

    remove_working_dir
else
    logger Installed Chromium version \(${INSTALLED_VERSION}\) is up-to-date. \
           No action needed.
fi

exit 0</pre>
</blockquote>
<p></code><br />
Next, I have a property list named <strong>~/Library/LaunchAgents/com.slaunchaman.chromium.plist</strong>:<br />
<code><br />
<blockquote>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd &gt;
&lt;plist version="1.0"&gt;
    &lt;dict&gt;
        &lt;key&gt;Label&lt;/key&gt;
        &lt;string&gt;com.slaunchaman.chromium&lt;/string&gt;
        &lt;key&gt;Program&lt;/key&gt;
        &lt;string&gt;/Users/slauncha/bin/chromiupdate&lt;/string&gt;
        &lt;key&gt;KeepAlive&lt;/key&gt;
        &lt;false/&gt;
        &lt;key&gt;StartInterval&lt;/key&gt;
        &lt;integer&gt;3600&lt;/integer&gt;
        &lt;key&gt;RunAtLoad&lt;/key&gt;
        &lt;true/&gt;
        &lt;key&gt;StandardOutPath&lt;/key&gt;
        &lt;string&gt;/dev/null&lt;/string&gt;
        &lt;key&gt;StandardErrorPath&lt;/key&gt;
        &lt;string&gt;/dev/null&lt;/string&gt;
    &lt;/dict&gt;
&lt;/plist&gt;</pre>
</blockquote>
<p></code></p>
<p>Finally, I have an AppleScript at <strong>~/Library/Scripts/Chromium Update Dialog.app</strong>:<br />
<code><br />
<blockquote>
<pre>display dialog "Chromium was just updated. You should restart it."</pre>
</blockquote>
<p></code></p>
<p>The LaunchAgent runs once an hour, checking to see if the installed version of Chromium is older than the latest snapshot. If so, it downloads it and uses <strong>rsync</strong> to copy the changes. The script places Chromium in <strong>~/Applications</strong>, but it shouldn’t be hard to modify to put it into /Applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.slaunchaman.com/2009/05/19/automatically-get-the-latest-chromium-snapshot-with-launchd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updated: Resizer AppleScript</title>
		<link>http://blog.slaunchaman.com/2008/05/28/updated-resizer-applescript/</link>
		<comments>http://blog.slaunchaman.com/2008/05/28/updated-resizer-applescript/#comments</comments>
		<pubDate>Wed, 28 May 2008 21:34:09 +0000</pubDate>
		<dc:creator>Jeff Kelley</dc:creator>
				<category><![CDATA[Mac Tips]]></category>
		<category><![CDATA[AppleScript]]></category>
		<category><![CDATA[meta]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://slaunchaman.wordpress.com/?p=29</guid>
		<description><![CDATA[After looking at my AppleScript to resize windows, I’ve decided to make a few updates.  Instead of manually doing the math for each resolution, I’ve created a new variable, desired_width, which is exactly what it sounds like: how wide you want your windows to be.  I’ve also made the other variable names more human-friendly: _nl [...]]]></description>
			<content:encoded><![CDATA[<p>After looking at my <a href="http://blog.slaunchaman.com/2008/05/20/resize-your-windows-automatically-for-different-resolutions/">AppleScript to resize windows</a>, I’ve decided to make a few updates.  Instead of manually doing the math for each resolution, I’ve created a new variable, <span style="color:#008000;">desired_width</span>, which is exactly what it sounds like: how wide you want your windows to be.  I’ve also made the other variable names more human-friendly: <span style="color:#008000;">_nl</span> and <span style="color:#008000;">_nr</span> are now <span style="color:#008000;">left_bound</span> and <span style="color:#008000;">right_bound</span>, respectively, for example.  After adding iTunes to my script, I noticed that it was being resized behind the menubar, so instead of setting the upper bound for all windows at 0, I’ve defined the variable <span style="color:#008000;">top_bound</span>, which defaults to 22 to account for the height of the menu bar.  If you find that this setting is incorrect (e.g. if you’ve enabled some accessibility settings that change font sizes and therefore the size of the menu bar) you may need to change it; I haven’t found a way to get the height of the menu bar in AppleScript yet—so far I’ve only found it in Java—so if anyone knows feel free to leave a comment.  Finally, after seeing <a href="http://www.j4mie.org/2008/05/26/how-to-get-the-dimensions-of-the-dock/trackback/">this post</a> by Jamie Matthews, I added some functionality to automatically set <span style="color:#008000;">bottom_bound</span> to the height of the Dock.</p>
<p>After all of these updates, the script now takes a desired width and moves applications that support AppleScript such that they range horizontally to your desired width, centered on the screen, and stretching from the bottom of the menu bar to the top of the Dock.  In the future, I’d like to make a separate application, perhaps AppleScript-based, that will allow for user customization of how the windows are arranged, allow for custom application settings, and perhaps Spaces integration.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.slaunchaman.com/2008/05/28/updated-resizer-applescript/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Resize Your Windows Automatically for Different Resolutions</title>
		<link>http://blog.slaunchaman.com/2008/05/20/resize-your-windows-automatically-for-different-resolutions/</link>
		<comments>http://blog.slaunchaman.com/2008/05/20/resize-your-windows-automatically-for-different-resolutions/#comments</comments>
		<pubDate>Tue, 20 May 2008 22:04:27 +0000</pubDate>
		<dc:creator>Jeff Kelley</dc:creator>
				<category><![CDATA[Mac Tips]]></category>
		<category><![CDATA[AppleScript]]></category>
		<category><![CDATA[convenience]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[MacBook Pro]]></category>
		<category><![CDATA[screen resolution]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://slaunchaman.wordpress.com/?p=17</guid>
		<description><![CDATA[I use my MacBook Pro in a few different scenarios: by itself, plugged in to a 21” Apple Cinema Display, or plugged in to a 24” Dell 2405FPW.  I’m also rather OCD; I prefer my Firefox/Safari, Mail.app, and Vienna windows to be centered, stretch from the menu bar to the top of my Dock, and [...]]]></description>
			<content:encoded><![CDATA[<p>I use my MacBook Pro in a few different scenarios: by itself, plugged in to a 21” Apple Cinema Display, or plugged in to a 24” Dell 2405FPW.  I’m also rather OCD; I prefer my Firefox/Safari, Mail.app, and Vienna windows to be centered, stretch from the menu bar to the top of my Dock, and be a certain width.  I created a small AppleScript to auto-detect my resolution and size the windows accordingly:</p>
<pre style="overflow:scroll;">
<blockquote>

tell application "Finder"
	set screen_resolution to bounds of window of desktop
	set screen_width to item 3 of screen_resolution
	set screen_height to item 4 of screen_resolution
end tell

tell application "System Events" to tell process "Dock"
	set dock_dimensions to size in list 1
	set dock_height to item 2 of dock_dimensions
end tell

set desired_width to 1400

set side_space to screen_width - desired_width
set left_bound to (side_space / 2)
set right_bound to left_bound + desired_width
set bottom_bound to screen_height - dock_height
set top_bound to 22 (* for the menu bar *)

try
	tell application "iTunes"
		activate
		set the bounds of the first window to {left_bound, top_bound, right_bound, bottom_bound}
	end tell
end try

try
	tell application "Firefox"
		activate
		set the bounds of the first window to {left_bound, top_bound, right_bound, bottom_bound}
	end tell
end try

try
	tell application "Mail"
		activate
		set the bounds of the first window to {left_bound, top_bound, right_bound, bottom_bound}
	end tell
end try

try
	tell application "Vienna"
		activate
		set the bounds of the first window to {left_bound, top_bound, right_bound, bottom_bound}
	end tell
end try</blockquote>
</pre>
<p>With that in place, I saved it as an application in <code>~/Applications</code>, and put it in my Dock.  Now, whenever I change resolutions, I just click the button and everything is how I like it.</p>
<p>To change the script, you should be able to add any application with an AppleScript dictionary that supports moving and sizing the window.  <span style="text-decoration: line-through;">The numbers I’ve used make the windows 1,400px wide, and the height that you want will depend on the size of your Dock.</span> The script moves windows to the center, <span style="color: #008000;">desired_width</span> wide, and from the menubar to the Dock.</p>
<p><strong>Note:</strong><em> </em>I have had some trouble recently; sometimes when I change my resolution the AppleScript doesn’t pick it up.  To combat this, I told the Displays System Preferences pane to keep its icon in the menu bar; when my script uses the incorrect resolution, I change my screen resolution then change it back, which is enough for the script to detect the change.</p>
<p><strong>Update 2008-05-28:</strong> Made some usability changes.  <a href="http://blog.slaunchaman.com/2008/05/28/updated-resizer-applescript/">Details here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.slaunchaman.com/2008/05/20/resize-your-windows-automatically-for-different-resolutions/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
	</channel>
</rss>
