<?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; scripting</title>
	<atom:link href="http://blog.slaunchaman.com/tag/scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.slaunchaman.com</link>
	<description>Mac tips, iPhone applications, and the like</description>
	<lastBuildDate>Thu, 19 Aug 2010 21:14:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Xcode 3.2: Using GDB as a Non-Admin User</title>
		<link>http://blog.slaunchaman.com/2010/07/20/xcode-3-2-using-gdb-as-a-non-admin-user/</link>
		<comments>http://blog.slaunchaman.com/2010/07/20/xcode-3-2-using-gdb-as-a-non-admin-user/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 18:30:35 +0000</pubDate>
		<dc:creator>Jeff Kelley</dc:creator>
				<category><![CDATA[Mac Systems Administration]]></category>
		<category><![CDATA[Programming Tips]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[dscl]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Systems Administration]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://blog.slaunchaman.com/?p=310</guid>
		<description><![CDATA[New in Xcode 3.2 is]]></description>
			<content:encoded><![CDATA[<p><a href="http://developer.apple.com/iphone/library/releasenotes/DeveloperTools/RN-Xcode/#//apple_ref/doc/uid/TP40001051-DontLinkElementID_13">New in Xcode 3.2</a> is an authorization setting that looks like this:</p>
<blockquote><pre>&lt;dict&gt;
	&lt;key&gt;allow-root&lt;/key&gt;
	&lt;false/&gt;
	&lt;key&gt;class&lt;/key&gt;
	&lt;string&gt;rule&lt;/string&gt;
	&lt;key&gt;comment&lt;/key&gt;
	&lt;string&gt;For use by Apple.  WARNING: administrators are advised not to
	        modify this right.&lt;/string&gt;
	&lt;key&gt;k-of-n&lt;/key&gt;
	&lt;integer&gt;1&lt;/integer&gt;
	&lt;key&gt;rule&lt;/key&gt;
	&lt;array&gt;
		&lt;string&gt;is-admin&lt;/string&gt;
		&lt;string&gt;is-developer&lt;/string&gt;
		&lt;string&gt;authenticate-developer&lt;/string&gt;
	&lt;/array&gt;
	&lt;key&gt;shared&lt;/key&gt;
	&lt;true/&gt;
&lt;/dict&gt;</pre>
</blockquote>
<p>The upshot of this is that if you aren’t in the <code>_developer</code> group in the local directory, you’ll have to authenticate as an administrator to use <code>gdb</code> or some of the performance tools. For the vast majority of developers on Mac OS X, who run as an administrator, this is fine, but if you’re running as a regular user, either for security reasons or because you’re in something like a lab setting, this can be a problem. To add a user to the <code>_developer</code> group, use the <code>dscl</code> command:</p>
<blockquote><p><code>dscl . -append /Groups/_developer GroupMembership <strong>UserName</strong></code></p></blockquote>
<p>Replace <code><strong>UserName</strong></code> with the short name of your user account (or <code>$(whoami)</code>) and you should be all set.</p>
<p>If you’re administering Mac OS X in a lab setting, you can either create a LaunchAgent that handles this or a login hook. See the Apple tech note <a href="http://developer.apple.com/mac/library/technotes/tn2008/tn2228.html">“Running At Login”</a> for more information on login hooks. As an added touch, my login and logout scripts to handle this also remove all users from the group, like so:</p>
<blockquote><p><code>dscl . -delete /Groups/_developer GroupMembership</code></p></blockquote>
<p>If the <code>GroupMembership</code> key doesn’t exist, <code>dscl</code> will create it—and it doesn’t exist by default—so deleting it outright shouldn’t cause any problems.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.slaunchaman.com/2010/07/20/xcode-3-2-using-gdb-as-a-non-admin-user/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dealing with Special Characters in iPhone 4 Graphics Filenames with Subversion</title>
		<link>http://blog.slaunchaman.com/2010/07/10/dealing-with-special-characters-in-iphone-4-graphics-filenames-with-subversion/</link>
		<comments>http://blog.slaunchaman.com/2010/07/10/dealing-with-special-characters-in-iphone-4-graphics-filenames-with-subversion/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 01:48:27 +0000</pubDate>
		<dc:creator>Jeff Kelley</dc:creator>
				<category><![CDATA[Programming Tips]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[convenience]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[iPhone 4]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[Subversion]]></category>

		<guid isPermaLink="false">http://blog.slaunchaman.com/?p=304</guid>
		<description><![CDATA[With the iPhone 4’s high-resolution]]></description>
			<content:encoded><![CDATA[<p>With the iPhone 4’s high-resolution screen, designers need to create two sets of art; the guidelines are to name the files like so: <code>SomeCoolImage.png</code> and <code>SomeCoolImage@2x.png</code>. Unfortunately, if you try to add these files to an SVN repository, the <code>@</code> symbol throws them off:</p>
<blockquote><pre>$ svn add Icon\@2x~iphone.png
svn: warning: 'Icon' not found</pre>
</blockquote>
<p>The fix, thanks to the <a href="http://groups.google.com/group/subversion_users/browse_thread/thread/2b8e8e05e04fa240/">subversion_users Google Group</a>, is to add another <code>@</code> to the end of the filename, like so:</p>
<blockquote><pre>$ svn add ./Icon\@2x~iphone.png@
A  (bin)  Icon@2x~iphone.png</pre>
</blockquote>
<p>If you’d like to do this for all of your high-resolution art in a folder, here’s a tiny Bash command for the task:</p>
<blockquote><pre>for x in `ls *\@*`; do svn add $x\@; done</pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.slaunchaman.com/2010/07/10/dealing-with-special-characters-in-iphone-4-graphics-filenames-with-subversion/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How-To: Run a LaunchDaemon That Requires Networking</title>
		<link>http://blog.slaunchaman.com/2010/07/01/how-to-run-a-launchdaemon-that-requires-networking/</link>
		<comments>http://blog.slaunchaman.com/2010/07/01/how-to-run-a-launchdaemon-that-requires-networking/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 17:28:37 +0000</pubDate>
		<dc:creator>Jeff Kelley</dc:creator>
				<category><![CDATA[Mac Systems Administration]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[launchd]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://blog.slaunchaman.com/?p=300</guid>
		<description><![CDATA[I’m a big fan of]]></description>
			<content:encoded><![CDATA[<p>I’m a big fan of using <a href="http://launchd.macosforge.org/">launchd</a> to automate things in Mac OS X. That serves me well, as that’s how Apple wants things done moving forward. That said, one of launchd’s biggest shortcomings is a lack of a dependency system. There is currently no way, for instance, to specify in a LaunchDaemon’s property list that the daemon requires the network to be active in order to run. This is problematic for some things, such as a script I wrote to automatically set the computer’s hostname based on the DNS server (more on that later). Luckily, Apple has already defined a function, <code>CheckForNetwork</code>, in <code>/private/etc/rc.common</code>. Here it is in all its glory:</p>
<blockquote><pre>##
# Determine if the network is up by looking for any non-loopback
# internet network interfaces.
##
CheckForNetwork()
{
	local test

	if [ -z "${NETWORKUP:=}" ]; then
		test=$(ifconfig -a inet 2>/dev/null | sed -n -e '/127.0.0.1/d' -e '/0.0.0.0/d' -e '/inet/p' | wc -l)
		if [ "${test}" -gt 0 ]; then
			NETWORKUP="-YES-"
		else
			NETWORKUP="-NO-"
		fi
	fi
}</pre>
</blockquote>
<p>In your code, simply include <code>rc.common</code>, then call <code>CheckForNetwork</code> as needed. An example:</p>
<blockquote><pre>#!/bin/bash

# Example Daemon Starter
. /etc/rc.common

CheckForNetwork

while [ "${NETWORKUP}" != "-YES-" ]
do
        sleep 5
        NETWORKUP=
        CheckForNetwork
done

# Now do what you need to do.</pre>
</blockquote>
<p>Note that this will keep the script running indefinitely until <code>CheckForNetwork</code> sets <code>NETWORKUP</code> to “<code>-YES-</code>,” so if there’s a networking problem your code may never execute.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.slaunchaman.com/2010/07/01/how-to-run-a-launchdaemon-that-requires-networking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating dyld Shared Caches with Radmind: Best Practices</title>
		<link>http://blog.slaunchaman.com/2010/06/15/updating-dyld-shared-caches-with-radmind-best-practices/</link>
		<comments>http://blog.slaunchaman.com/2010/06/15/updating-dyld-shared-caches-with-radmind-best-practices/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 15:41:56 +0000</pubDate>
		<dc:creator>Jeff Kelley</dc:creator>
				<category><![CDATA[Mac Systems Administration]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[dyld]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Radmind]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[Systems Administration]]></category>

		<guid isPermaLink="false">http://blog.slaunchaman.com/?p=280</guid>
		<description><![CDATA[Similar to my last post]]></description>
			<content:encoded><![CDATA[<p>Similar to my last post about <a href="http://blog.slaunchaman.com/2010/05/27/updating-kernel-extensions-with-radmind-best-practices/">updating kernel extensions</a>, you can run into problems with Radmind due to the dyld shared cache. You may see messages like this in your system log:</p>
<blockquote><p><code>current cache invalid because /System/Library/Frameworks/WebKit.framework/Versions/A/WebKit has changed</code></p></blockquote>
<p>Running the <code>update_dyld_shared_cache</code> command will fix this, but there&#8217;s a better way. Sure, there&#8217;s almost no overhead to that command, but where&#8217;s the fun in that? Here&#8217;s a pre-apply script that will delete any shared caches that have changed, which will then be re-built at reboot.</p>
<blockquote><p><code>
<pre>#!/bin/sh

# update_dyld_caches: Inspects the applicable transcript for something that
#                     might cause a dyld cache to become outdated. If it exists,
#                     delete the cache so it's re-created at startup.

DYLD_CACHE_FOLDER="/private/var/db/dyld"
DYLD_PREFIX="dyld_shared_cache_"
ARCHITECTURES="i386 x86_64 rosetta ppc ppc64"

for arch in ${ARCHITECTURES}; do
	cache="${DYLD_CACHE_FOLDER}/${DYLD_PREFIX}${arch}"
	map="${DYLD_CACHE_FOLDER}/${DYLD_PREFIX}${arch}.map"

	if /bin/test -f "${cache}"; then
		if /bin/test -f "${map}"; then
			/bin/cat "${map}" | grep ^/ | sort --unique --ignore-case | while read line; do
				if /bin/test -n "$(grep ${line} ${1})"; then # found a match
					/bin/rm -f "${cache}"
					/bin/rm -f "${map}"
					break;
				fi
			done
		else
			# Cache exists, but there's no map.
			/bin/rm -f "${cache}"
		fi
	fi
done</pre>
<p></code></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.slaunchaman.com/2010/06/15/updating-dyld-shared-caches-with-radmind-best-practices/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating Kernel Extensions with Radmind: Best Practices</title>
		<link>http://blog.slaunchaman.com/2010/05/27/updating-kernel-extensions-with-radmind-best-practices/</link>
		<comments>http://blog.slaunchaman.com/2010/05/27/updating-kernel-extensions-with-radmind-best-practices/#comments</comments>
		<pubDate>Thu, 27 May 2010 17:28:36 +0000</pubDate>
		<dc:creator>Jeff Kelley</dc:creator>
				<category><![CDATA[Mac Systems Administration]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Kernel Extensions]]></category>
		<category><![CDATA[kextd]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Radmind]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[Systems Administration]]></category>

		<guid isPermaLink="false">http://blog.slaunchaman.com/?p=272</guid>
		<description><![CDATA[One of the problems that]]></description>
			<content:encoded><![CDATA[<p>One of the problems that I&#8217;ve run into so far using <a href="http://www.radmind.org">Radmind</a> to manage Mac OS X—specifically, the Leopard to Snow Leopard transition—is that <code>kextd</code> helpfully starts recreating your kernel extension cache as soon as you modify anything in <code>/System/Library/Extensions</code>. This can be problematic when you&#8217;re updating core system files; as you update the 10.5 kernel extensions to their 10.6 counterparts, you don&#8217;t want the 10.5 version of <code>kextd</code> creating a cache of 10.6 kernel extensions, especially as the kernel extension cache has moved (from <code>/System/Library/Extensions.mkext</code> to <code>/System/Library/Caches/com.apple.kext.caches/</code>). So, should you handle this? My solution is to stop <code>kextd</code> if I know that I&#8217;m updating kernel extensions; that way, they won&#8217;t be re-created until reboot. Here&#8217;s the script:</p>
<p><code>/private/var/radmind/preapply/update_kernel_extensions</code>:</p>
<blockquote><p><code>
<pre>#!/bin/sh

# update_kernel_extensions: Manage the replacement of old kernel extensions.
#                           If there are updates, kill kextd and destroy the
#                           caches.

KEXT_CACHE="/System/Library/Caches/com.apple.kext.caches"
KEXT_FOLDER="/System/Library/Extensions"
KEXTD_LAUNCHD="com.apple.kextd"
SYSTEM_LAUNCHD_FOLDER="/System/Library/LaunchDaemons"

transcript="${1}"
result="${transcript}.$$"

/usr/bin/grep "${KEXT_FOLDER}" "${transcript}" > "${result}"

if test -n "${result}"; then #result is non-empty
    # Disable kextd to prevent it from recreating kernel extension caches, which
    # will be re-created at startup.
    if test -n "$(/bin/launchctl list | /usr/bin/grep ${KEXTD_LAUNCHD})"; then
        #kextd is running
        /bin/launchctl unload "${SYSTEM_LAUNCHD_FOLDER}/${KEXTD_LAUNCHD}.plist"
    fi

    # Remove kernel extension cache.
    /bin/rm -rf "${KEXT_CACHE}"
fi

rm -f "${result}"</pre>
<p></code></p></blockquote>
<p>In its present form, it only works on Snow Leopard, but I&#8217;ll be updating it to work on Leopard as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.slaunchaman.com/2010/05/27/updating-kernel-extensions-with-radmind-best-practices/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using AppleScript to Automate an iChat Video Chat</title>
		<link>http://blog.slaunchaman.com/2010/03/30/using-applescript-to-automate-an-ichat-video-chat/</link>
		<comments>http://blog.slaunchaman.com/2010/03/30/using-applescript-to-automate-an-ichat-video-chat/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 16:53:09 +0000</pubDate>
		<dc:creator>Jeff Kelley</dc:creator>
				<category><![CDATA[Mac Tips]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[AppleScript]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[iChat]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://blog.slaunchaman.com/?p=256</guid>
		<description><![CDATA[I had to write a script to automatically start iChat at login and start a video chat with a specified screenname. I wanted to only start the chat if the user was online and available, and quit iChat on an error or if the chat ended.]]></description>
			<content:encoded><![CDATA[<p>I had to write a script to automatically start iChat at login and start a video chat with a specified screenname. I wanted to only start the chat if the user was online and available, and quit iChat on an error or if the chat ended. So here’s the script I have:</p>
<pre style="overflow:auto;"><strong>using terms from</strong> <em><span style="color: #0000ff;">application</span></em> "iChat"
	<strong>tell</strong> <em><span style="color: #0000ff;">application</span></em> "iChat"
		<strong><span style="color: #0000ff;">activate</span></strong>
		<span style="color: #0000ff;"><strong>log in</strong></span>
		<span style="color: #333399;"><strong>delay</strong></span> 5
		<strong>set</strong> <span style="color: #008000;">theBuddy</span> <strong>to</strong> <em><span style="color: #0000ff;">buddy</span></em> "ScreennameGoesHere" <strong>of</strong> <em><span style="color: #0000ff;">service</span></em> "AIM"
		<strong>try</strong>
			<strong>set</strong> <span style="color: #008000;">theStatus</span> <strong>to</strong> <span style="color: #333399;">status</span> <strong>of</strong> <span style="color: #008000;">theBuddy</span>
		<strong>on error</strong> <span style="color: #008000;">errmesg</span> <span style="color: #0000ff;">number</span> <span style="color: #008000;">errno</span>
			<strong>set</strong> <span style="color: #008000;">message</span> <strong>to</strong> <span style="color: #333399;"><strong>display dialog</strong></span> "The user is currently unavailable." <span style="color: #333399;">buttons</span> {"OK"}
			<strong><span style="color: #0000ff;">quit</span></strong>
			<strong>return</strong>
		<strong>end try</strong>
		<strong>if</strong> <span style="color: #008000;">theStatus</span> <strong>is</strong> <span style="color: #333399;">available</span> <strong>then</strong>
			<strong>set</strong> <span style="color: #008000;">theCapabilities</span> <strong>to get</strong> <span style="color: #0000ff;">capabilities</span> <strong>of</strong> <span style="color: #008000;">theBuddy</span>
			<strong>if</strong> (<span style="color: #008000;">theCapabilities</span> <strong>contains</strong> <span style="color: #333399;">multiperson video</span>) <strong>then</strong>
				<span style="color: #0000ff;"><strong>send</strong></span> "A user is attempting to contact you." <span style="color: #0000ff;">to</span> <span style="color: #008000;">theBuddy</span>
				<span style="color: #333399;"><strong>delay</strong></span> 2
				<strong>tell</strong> <span style="color: #0000ff;"><em>service</em></span> "AIM" <strong>to</strong> <span style="color: #0000ff;"><strong>make</strong></span> <span style="color: #0000ff;"><em>video chat</em></span> <span style="color: #0000ff;">with properties</span> {participants:<span style="color: #008000;">theBuddy</span>}
				<strong>set</strong> <span style="color: #008000;">theChat</span> <strong>to</strong> <span style="color: #333399;">result</span>
				<span style="color: #333399;"><strong>delay</strong></span> 30
				<strong>try</strong>
					<strong>set</strong> <span style="color: #008000;">theStatus</span> <strong>to the</strong> <span style="color: #333399;">av connection status</span> <strong>of</strong> <span style="color: #008000;">theChat</span>
				<strong>on error</strong> <span style="color: #008000;">errmesg</span> <span style="color: #0000ff;">number</span> <span style="color: #008000;">errno</span>
					<strong><span style="color: #0000ff;">quit</span></strong>
					<strong>return</strong>
				<strong>end try</strong>
				<strong>repeat while</strong> <span style="color: #008000;">theStatus</span> <strong>is not</strong> <span style="color: #333399;">ended</span>
					<span style="color: #333399;"><strong>delay</strong></span> 5
					<strong>try</strong>
						<strong>set</strong> <span style="color: #008000;">theStatus</span> <strong>to the</strong> <span style="color: #333399;">av connection status</span> <strong>of</strong> <span style="color: #008000;">theChat</span>
					<strong>on error</strong> <span style="color: #008000;">errmesg</span> <span style="color: #0000ff;">number</span> <span style="color: #008000;">errno</span>
						<strong><span style="color: #0000ff;">quit</span></strong>
						<strong>return</strong>
					<strong>end try</strong>
				<strong>end repeat</strong>
				<strong><span style="color: #0000ff;">quit</span></strong>
				<strong>return</strong>
			<strong>else</strong>
				<strong>set</strong> <span style="color: #008000;">message</span> <strong>to</strong> <span style="color: #333399;"><strong>display dialog</strong></span> "The user cannot video chat at this time. Please try again later." <span style="color: #333399;">buttons</span> {"OK"}
				<span style="color: #0000ff;"><strong>quit</strong></span>
				<strong>return</strong>
			<strong>end if</strong>
		<strong>else</strong>
			<strong>set</strong> <span style="color: #008000;">message</span> <strong>to</strong> <span style="color: #333399;"><strong>display dialog</strong></span> "The user is currently unavailable." <span style="color: #333399;">buttons</span> {"OK"}
			<strong><span style="color: #0000ff;">quit</span></strong>
			<strong>return</strong>
		<strong>end if</strong>
	<strong>end tell</strong>
<strong>end using terms from</strong></pre>
<p>A couple of gotchas:</p>
<ul>
<li>I tried using <span style="color: #333399;"><code>video chat</code></span> instead of <span style="color: #333399;"><code>multiperson video</code></span>, but that always returned false. I don’t know why.</li>
<li>Once the video chat has ended, you can’t poll its status (hence the <strong><code>try</code></strong> block).</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.slaunchaman.com/2010/03/30/using-applescript-to-automate-an-ichat-video-chat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Apple&#8217;s SimplePing on iPhone OS</title>
		<link>http://blog.slaunchaman.com/2010/02/13/using-apples-simpleping-on-iphone-os/</link>
		<comments>http://blog.slaunchaman.com/2010/02/13/using-apples-simpleping-on-iphone-os/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 19:06:48 +0000</pubDate>
		<dc:creator>Jeff Kelley</dc:creator>
				<category><![CDATA[Programming Tips]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[ping]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://blog.slaunchaman.com/?p=203</guid>
		<description><![CDATA[If you try out of]]></description>
			<content:encoded><![CDATA[<p>If you try out of the box to compile Apple&rsquo;s &ldquo;<a href="http://developer.apple.com/mac/library/samplecode/SimplePing/">SimplePing</a>&rdquo; code sample on the iPhone OS, you&rsquo;ll wind up with a lot of errors as some files don&rsquo;t exist in those SDKs. Specifically, you need these files (you need more than <em>just</em> these files to compile, obviously, but these are the ones that aren&rsquo;t included):</p>
<ul>
<li><code>/usr/include/netinet/ip.h</code></li>
<li><code>/usr/include/netinet/in_systm.h</code></li>
<li><code>/usr/include/netinet/ip_icmp.h</code></li>
<li><code>/usr/include/netinet/ip_var.h</code></li>
</ul>
<p>So here&rsquo;s a quick Bash script that links the relevant files to your iPhone OS and iPhone Simulator SDKs:<br />
<code>
<pre>for path in /Developer/Platforms/iPhone*/Developer/SDKs/*; do
    for file in /usr/include/netinet/ip.h \
                /usr/include/netinet/in_systm.h \
                /usr/include/netinet/ip_icmp.h \
                /usr/include/netinet/ip_var.h; do
        if [ ! -f "${path}${file}" ]; then
            sudo ln "${file}" "${path}${file}"
        fi;
    done;
done</pre>
<p></code><br />
I&rsquo;ve spoken to an Apple engineer and confirmed that this is the best way to do it, as well as filed a bug, which I encourage <a href="http://bugreport.apple.com">you to do as well</a> if this annoys you.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.slaunchaman.com/2010/02/13/using-apples-simpleping-on-iphone-os/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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]]></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>Computers are Disgusting</title>
		<link>http://blog.slaunchaman.com/2008/07/18/computers-are-disgusting/</link>
		<comments>http://blog.slaunchaman.com/2008/07/18/computers-are-disgusting/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 19:42:39 +0000</pubDate>
		<dc:creator>Jeff Kelley</dc:creator>
				<category><![CDATA[Miscellania]]></category>
		<category><![CDATA[gross]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://blog.slaunchaman.com/?p=63</guid>
		<description><![CDATA[My run-in with some gross realities in dealing with computers.]]></description>
			<content:encoded><![CDATA[<p>I recently wrote a script to automatically install firmware updates for our Macs.  The problem with them is that for some, you have to hold down the power button to finish the installation after the machine has turned itself off.  Now I don’t know about you, but I sure as hell don’t want to go around to 900 or so Macs and hold down their power button after installing an update.  This script, while it can’t hold down the button for me, does allow student staff to automate the proces up to that point.  I don’t have to give them a password they could use to break the system, they can do the update for me, everybody wins.  It’s a beautiful system.</p>
<p>Well, today, I was testing the script out.  The problem with testing it is that you can only test a given computer once; once the firmware update is installed, it won’t show up as needing to be installed anymore.  So, I packed up my stuff and went to our biggest computer lab to do some testing.  My test subjects were some “CyberStations,” computers we have with basic web-browsing and e-mail loadsets.  They’re relatively unused during the summer, so if I broke any it wouldn’t be a big deal.  I went up to one, ran the update, and waited.  That’s when smoke came out of the back of the computer as the update ran.  <em>Oh shit</em>, I thought, <em>this thing is on fire!</em></p>
<p>Let’s go back a minute to my description of CyberStations.  Their loadset consists of a vanilla Mac OS X Leopard install with some applications taken out, Firefox, Thunderbird, and Adium.  Basically, it has the Apple-provided web browser, e-mail client, and IM program, as well as the leading open-source alternative for each.  Nothing on these computers is too taxing.  As a consequence, the fans never need to run too heavily, as the computer never really gets too hot.</p>
<p>Back to the smoking machine.  I was sure it was on fire—where there’s smoke, there’s fire, right?  Well, the student employee to whom I was demonstrating the script wasn’t too sure.  He placed his hand on the back of the computer (an iMac G5, not that it matters) and didn’t feel any heat.  So, if it wasn’t smoke, what was it?  That’s when I realized what had happened.  The fans, never having been run too hard, hadn’t been blowing a whole lot of dust around.  When they ran full speed during the firmware update, dust had come flying out of the computer’s vents.  A white, puffy cloud composed largely of the dead skin cells that had fallen off of our users’ skin for years.  It was coming out of the bottom, out of the back, and even where the screen met the case.  I quickly held my breath and stepped back.</p>
<p>I’m really glad that we have student staff to do the rest of this.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.slaunchaman.com/2008/07/18/computers-are-disgusting/feed/</wfw:commentRss>
		<slash:comments>1</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]]></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>
	</channel>
</rss>
