<?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>toastup! &#187; Code Journal</title>
	<atom:link href="http://toastycode.com/blog/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://toastycode.com/blog</link>
	<description>updates from toastycode</description>
	<lastBuildDate>Sun, 06 Sep 2009 04:48:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Ordering System Preferences around.</title>
		<link>http://toastycode.com/blog/2007/12/12/ordering-system-preferences-around/</link>
		<comments>http://toastycode.com/blog/2007/12/12/ordering-system-preferences-around/#comments</comments>
		<pubDate>Wed, 12 Dec 2007 05:28:36 +0000</pubDate>
		<dc:creator>Daniel Sandler</dc:creator>
				<category><![CDATA[Code Journal]]></category>
		<category><![CDATA[Cuckoo]]></category>

		<guid isPermaLink="false">http://toastycode.com/blog/2007/12/12/ordering-system-preferences-around/</guid>
		<description><![CDATA[Just a quick note: the following very useful tidbit was added to System Preferences&#8217; AppleScript dictionary in Leopard. tell application &#34;System Preferences&#34; activate reveal pane id &#34;com.toastycode.Cuckoo&#34; end tell That is, you can use reveal pane localizedName or reveal pane id bundleId to tell SysPrefs to switch to a given prefPane. This is an improvement [...]]]></description>
			<content:encoded><![CDATA[<p>
Just a quick note: the following very useful tidbit was added to System Preferences&#8217; AppleScript dictionary in Leopard.</p>
<pre>
<b>tell application</b> &quot;System Preferences&quot;
    activate
    <span style="background-color:yellow;">reveal pane id &quot;com.toastycode.Cuckoo&quot;</span>
<b>end tell</b>
</pre>
<p>
That is, you can use <code>reveal pane <i>localizedName</i></code> or <code>reveal pane id <i>bundleId</i></code> to tell SysPrefs to switch to a given <code>prefPane</code>.  This is an improvement on <code>reveal</code> in earlier versions of the OS, which only supported the <code>reveal anchor <i>someTabName</i> in pane <i>name</i></code> phrasing, which doesn&#8217;t fly if your preference pane doesn&#8217;t have tabs.  (As noted <a href="http://macscripter.net/articles/468_0_10_29_C/">here</a>, you can use the pseudo-anchor <code>main</code> on Apple&#8217;s tabless prefPanes, but I couldn&#8217;t find any kind of documentation on how to add &#8220;main&#8221; to my own prefPane.)
</p>
<p>If you try the 10.5-style <code>reveal pane</code> syntax on Tiger and earlier, you&#8217;ll be rewarded with a less-than-elucidating <code>NSReceiversCantHandleCommandScriptError</code>.  (Try saying that three times fast. Or, uh, once.)</p>
<p>The following AppleScript will work on all releases of Mac OS X, however:</p>
<pre>
<b>tell application</b> &quot;System Preferences&quot;
    activate
    <i>-<tt></tt>- works in 10.4 and 10.5</i>
    <span style="background-color:yellow;"><b>set</b> current pane <b>to</b> pane id &quot;com.toastycode.Cuckoo&quot;</span>
<b>end tell</b>
</pre>
<p>
Just thought I&#8217;d share in case there&#8217;s some other poor soul out there trying to launch a specific preference panel from AppleScript or Cocoa.
</p>]]></content:encoded>
			<wfw:commentRss>http://toastycode.com/blog/2007/12/12/ordering-system-preferences-around/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Leopard-compatible.</title>
		<link>http://toastycode.com/blog/2007/10/29/leopard-compatible/</link>
		<comments>http://toastycode.com/blog/2007/10/29/leopard-compatible/#comments</comments>
		<pubDate>Mon, 29 Oct 2007 21:54:44 +0000</pubDate>
		<dc:creator>Daniel Sandler</dc:creator>
				<category><![CDATA[Code Journal]]></category>
		<category><![CDATA[Cuckoo]]></category>

		<guid isPermaLink="false">http://toastycode.com/blog/2007/10/29/leopard-compatible/</guid>
		<description><![CDATA[I got my hands on a Leopard machine today to verify that all toastycode screen savers and tools work perfectly in Leopard, a.k.a. Mac OS X 10.5. (And they do.) Feel free to upgrade, toasty users! My only gripe: Why does the new Finder take Cuckoo&#8217;s pretty birdhouse icon and cram it into a tiny [...]]]></description>
			<content:encoded><![CDATA[<p>
I got my hands on a Leopard machine today to verify that all toastycode <a href="/pyrotheque">screen savers</a> and <a href="/cuckoo">tools</a> work perfectly in Leopard, a.k.a. Mac OS X 10.5. (And they do.) Feel free to upgrade, toasty users!
</p>
<p>
My only gripe: Why does the new Finder take Cuckoo&#8217;s pretty birdhouse icon and cram it into a tiny little badge stamped on a generic &#8220;PREF&#8221; document?  You can barely see it, even at 128&times;128 pixels (see below). For shame.
</p>
<p align="center">
<img src="http://dsandler.org/entries/images/2007/cuckoo-leopard-icon.png" />
<div style="text-align: center; margin-top: 0.5em; font-size: 90%;"><b>Fig. 1.</b> &nbsp; Hey, I worked hard on that icon&hellip;</div>
</p>]]></content:encoded>
			<wfw:commentRss>http://toastycode.com/blog/2007/10/29/leopard-compatible/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Login items, continued</title>
		<link>http://toastycode.com/blog/2007/10/03/login-items-continued/</link>
		<comments>http://toastycode.com/blog/2007/10/03/login-items-continued/#comments</comments>
		<pubDate>Wed, 03 Oct 2007 17:54:38 +0000</pubDate>
		<dc:creator>Daniel Sandler</dc:creator>
				<category><![CDATA[Code Journal]]></category>

		<guid isPermaLink="false">http://toastycode.com/blog/2007/10/03/login-items-continued/</guid>
		<description><![CDATA[Following up on my loginitem script, Nick writes: I was wondering if this script could be modified to remove all login items from all users and not just the currently logged in one? We have about 30 computers with at least 6 users each that we need to remove all the login items from. Think [...]]]></description>
			<content:encoded><![CDATA[<p>
Following up on my <a href="http://toastycode.com/blog/2007/07/25/loginitem/">loginitem script</a>, Nick writes:
</p>
<blockquote>
I was wondering if this script could be modified to remove all login items from all users and not just the currently logged in one?  We have about 30 computers with at least 6 users each that we need to remove all the login items from.

Think it would be possible?
</blockquote>
<p>
It turns out that because <tt>loginitem</tt> uses AppleScript to ask <tt>System Events.app</tt> to do the work, it&#8217;s fundamentally limited to operating on the current user&#8217;s login items.  We&#8217;ll need some other way of manipulating those settings.  Fortunately, this particular problem (deleting all login items) has a convenient solution.
</p>
<P>Referring back to <a href="http://developer.apple.com/documentation/MacOSX/Conceptual/BPSystemStartup/Articles/CustomLogin.html#//apple_ref/doc/uid/20002134-SW2">Apple&#8217;s documentation</a>, we see that a user&#8217;s login items are stored in <tt>~/Library/Preferences/loginitem.plist</tt>.  For a single user, it&#8217;s sufficient to delete the <b>AutoLaunchedApplicationDictionary</b> key and log out and in again, but we&#8217;re trying to automate this process across a number of users.
</p>
<p>
Here, finally, is the recipe:
</p>
<ol>
<li>Create a &#8220;pristine&#8221; version of <tt>loginitem.plist</tt>, with no login items in it.  You might do this by opening <tt>~/Library/Preferences/loginitem.plist</tt> in Property List Editor and deleting the <b>AutoLaunchedApplicationDictionary</b> key, or by running the command:
<pre>defaults delete loginwindow &#x5c;
     AutoLaunchedApplicationDictionary</pre>
</li>
<li>Stash that file somewhere:
<pre>cp ~/Library/Preferences/loginitem.plist /tmp/</pre></li>
<li>Run:<pre>for aHome in /Users/*; do
  sudo cp /tmp/loginitem.plist &#x5c;
    $aHome/Library/Preferences/
done</pre></li>
</ol>
<p>
[Theoretically it should suffice to simply <em>delete</em> the <tt>loginitem.plist</tt> file, since the remaining values in that file (BuildVersionStampAsNumber, etc.) seem like the sort of things that the system could re-create for you. I don't know if it does, though, so the safest bet is to preserve them.]
</p>
<p>
<b>Exercise:</b> Convert your pristine <tt>loginitem.plist</tt> to text (either with <tt>defaults read</tt> or <tt>plutil</tt>); embed in a script; ssh in parallel to all the Macs in your lab, downloading and running the script on each.
</p>]]></content:encoded>
			<wfw:commentRss>http://toastycode.com/blog/2007/10/03/login-items-continued/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A shell tool for Mac login items.</title>
		<link>http://toastycode.com/blog/2007/07/25/loginitem/</link>
		<comments>http://toastycode.com/blog/2007/07/25/loginitem/#comments</comments>
		<pubDate>Thu, 26 Jul 2007 04:45:05 +0000</pubDate>
		<dc:creator>Daniel Sandler</dc:creator>
				<category><![CDATA[Code Journal]]></category>

		<guid isPermaLink="false">http://toastycode.com/blog/2007/07/25/a-shell-tool-for-mac-login-items/</guid>
		<description><![CDATA[Manipulating login items (you know, the apps that launch when you log into your Mac) from code is tricky. Apple suggests a number of ways to do it; the least painful seems to be to use AppleScript to do it (and that&#8217;s certainly not to say that it&#8217;s not plenty painful, too). The recent Cuckoo [...]]]></description>
			<content:encoded><![CDATA[<p>
Manipulating login items (you know, the apps that launch when you log into your Mac) from code is tricky.  Apple suggests <a href="http://developer.apple.com/documentation/MacOSX/Conceptual/BPSystemStartup/Articles/CustomLogin.html">a number of ways to do it</a>; the least painful seems to be to use AppleScript to do it (and that&#8217;s certainly not to say that it&#8217;s not plenty <a href="http://www.cocoadev.com/index.pl?StartingMyAppOnStartup">painful</a>, too).  
The recent <a href="http://toastycode.com/blog/2007/07/24/bug-fix-release-cuckoo-111/">Cuckoo bug fix</a> revolved around some AppleScript that works fine for most users, but blows up inscrutably in rare cases (in particular under 10.5 &#8220;Leopard&#8221;).
</p>
<p>
While testing the new release I cooked up <a href="/files/loginitem.txt"><code>loginitem</code></a>, a command-line tool that can be used to quickly add, remove, query, and list all the login items for the currently logged-in user.  It&#8217;s a Python script that uses the Objective-C bridge and AppleScript to bark orders at System Events to get the job done.  I found it to be safer than <a href="http://www.macosxhints.com/article.php?story=20050316020738829">screwing around with <code>defaults</code></a> and more convenient than fishing through System Preferences.  You could conceivably employ this script as part of a software installer, or use it while isolating a login item that&#8217;s giving you trouble (a technique suggested <a href="http://www.macosxhints.com/article.php?story=20051128060843412">here</a>).  It does quite a bit, so there are probably other uses I haven&#8217;t thought of as well.
</p>
<p>Here&#8217;s an example session with <code>loginitem</code>:</p>
<blockquote>
<p>Set Terminal to launch on login:</p>
<code>$ loginitem --add /Applications/Utilities/Terminal.app</code>
<p>Did it work?:</p>
<code>$ loginitem --exists Terminal \<br/>&nbsp; &nbsp; &#038;&#038; echo "yup, it worked"<br/>
<i>yup, it worked</i></code>
<p>Let&#8217;s see it another way:</p>
<code>$ loginitem --list<br/>
<i>[...]<br/>
Terminal<br/>
[...]</i><br/>
$ loginitem -<i></i>-list-paths<br/>
<i>[...]<br/>
/Applications/Utilities/Terminal.app<br/>
[...]</i><br/>
</code>
<p>On second thought, no, don&#8217;t bother:</p>
<code>$ loginitem --remove Terminal</code>
<p>Hey, what happens if we try that again?</p>
<code>$ loginitem --remove Terminal<br/>
<i>error: login item "Terminal" does not exist</i></code>
</blockquote>
<p>
Note that the results returned from <code>--list</code> are UTF-8 encoded localized names, so if you&#8217;ve got an app whose name in the Finder has non-ASCII characters (<a href="http://quicksilver.blacktree.com/">Quicksilver</a> is egregious in this respect), just be careful.</p>
<p>The <a href="/files/loginitem.txt"><code>loginitem</code> script</a> is freely available under a BSD license.  Please <a href="javascript:document.location='mai'+'lto:dsandler!toastycode'.replace(/!/,'@')+'.com';">get in touch</a> if you find bugs or have suggestions.</p>]]></content:encoded>
			<wfw:commentRss>http://toastycode.com/blog/2007/07/25/loginitem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

