<?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>n8blog &#187; Scripting</title>
	<atom:link href="http://www.n8gray.org/blog/category/apple/scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.n8gray.org</link>
	<description>distraction in action</description>
	<lastBuildDate>Thu, 01 Jul 2010 18:21:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Somebody Noticed.</title>
		<link>http://www.n8gray.org/blog/2007/03/16/somebody-noticed/</link>
		<comments>http://www.n8gray.org/blog/2007/03/16/somebody-noticed/#comments</comments>
		<pubDate>Sat, 17 Mar 2007 06:03:47 +0000</pubDate>
		<dc:creator>n8</dc:creator>
				<category><![CDATA[OS X]]></category>
		<category><![CDATA[ScriptExport]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.n8gray.org/blog/2007/03/16/somebody-noticed/</guid>
		<description><![CDATA[It looks like the MacWeb has finally noticed my baby!  No, not that one.  The ugly one.  And hey, I got a shout out from no less than John Gruber, which probably single-handedly advances me a degree or two closer to Kevin Bacon.

It&#8217;s a nice feeling to see your name in the [...]]]></description>
			<content:encoded><![CDATA[<p>It looks like the <a href="http://www.tuaw.com/2007/03/16/scriptexport-iphoto-plugin-allows-shell-script-manipulation/">MacWeb</a> has finally <a href="http://havegnuwilltravel.apesseekingknowledge.net/2007/03/fun-with-iphoto.html">noticed</a> my baby!  No, not <a href="http://www.n8gray.org/photos/amaya-may-2006/DSC_2040">that one</a>.  <a href="http://www.n8gray.org/code/scriptexport/">The ugly one</a>.  And hey, I got a shout out from no less than <a href="http://daringfireball.net/linked/2007/march#fri-16-scriptexport">John Gruber</a>, which probably single-handedly advances me a degree or two closer to Kevin Bacon.</p>

<p>It&#8217;s a nice feeling to see your name in the blogs you read on a daily basis, even if it happens on a Friday at 10PM <span class="caps">PST </span>and by Monday I&#8217;ll be the only one who remembers this ever happened.  Maybe this is the push I need in order to finally get this thing to v1.0 status.</p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.n8gray.org%2Fblog%2F2007%2F03%2F16%2Fsomebody-noticed%2F&amp;linkname=Somebody%20Noticed."><img src="http://www.n8gray.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.n8gray.org/blog/2007/03/16/somebody-noticed/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Command-Line Color Matching on OS X</title>
		<link>http://www.n8gray.org/blog/2006/04/27/command-line-color-matching-on-os-x/</link>
		<comments>http://www.n8gray.org/blog/2006/04/27/command-line-color-matching-on-os-x/#comments</comments>
		<pubDate>Fri, 28 Apr 2006 04:12:00 +0000</pubDate>
		<dc:creator>n8</dc:creator>
				<category><![CDATA[Photography]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.n8gray.org/sandbox/wordpress/?p=47</guid>
		<description><![CDATA[
Taking so many pictures of Amaya really expanded my horizons for photography and whetted my appetite for more serious gear, so a few months ago I picked up a new Nikon D50 DSLR.  It&apos;s a pretty sweet camera, instantly responding to any command, whether it&apos;s power-on, autofocus, shutter release, or even scrolling through images [...]]]></description>
			<content:encoded><![CDATA[<p>
Taking so many pictures of Amaya really expanded my horizons for photography and whetted my appetite for more serious gear, so a few months ago I picked up a new Nikon <span class="caps">D50 DSLR. </span> It&apos;s a pretty sweet camera, instantly responding to any command, whether it&apos;s power-on, autofocus, shutter release, or even scrolling through images on the <span class="caps">LCD. </span> As you would expect, it has lots and lots of obscure configuration options that I naturally wanted to play with.<br />
<p>
At some point I set it up to take photos in the <a href="http://en.wikipedia.org/wiki/Adobe_RGB">Adobe <span class="caps">RGB</span></a> color space, which can represent a wider range of colors than the <a href="http://en.wikipedia.org/wiki/SRGB_color_space">sRGB</a> color space that most consumer digital cameras use and the <span class="caps">D50 </span>uses by default.  (sRGB is the &#8220;lowest common denominator&#8221; color space, designed to represent the colors that a cheap-o 1986-era <span class="caps">CRT </span>monitor could reproduce.)  This is just fine, so long as all I want to do is view my photos on my nice color-managed Mac, but the world is full of color-crippled Windows and Linux apps.  (Actually, even the OS X version of Firefox is crippled.)  These apps don&apos;t know squat about color spaces &#8212; they just push the <span class="caps">RGB </span>values in the file straight to the monitor, and monitors are set up to act like sRGB devices by default.<br />
<p>
To make a long story short, if I simply upload an Adobe <span class="caps">RGB </span>photo to my website, 97% of the world (basically anybody who&apos;s not using Safari on OS X) will see something totally different than I do, because they&apos;ll be treating it like an sRGB photo.  They&apos;ll see a photo with dull, drab colors.  What&apos;s needed is to do a conversion to sRGB before uploading.<br />
<p>
So I started looking for utilities to do color conversion in bulk at the command line.  It was surprisingly hard to find information about this!  Most pros use Photoshop for this, and those who aren&apos;t pros generally don&apos;t have a clue about color spaces.  It turns out there are a few options.  There is an open-source color management system (CMS) called <a href="http://www.littlecms.com/">&#8220;Little <span class="caps">CMS</span>&#8220;</a> that includes a utility called &#8220;jpegicc&#8221; for color matching jpeg files.  Unfortunately, this program strips all the <span class="caps">EXIF </span>tags from the file.  There&apos;s also the &#8220;convert&#8221; command from the <a href="http://www.imagemagick.org">ImageMagick</a> project, which in newer versions can be linked to Little <span class="caps">CMS </span>to enable color conversion.  This works much better, preserving all of the <span class="caps">EXIF </span>tags from the original file and offering lots of other nifty options as well.  <br />
<p>
If you&apos;re using Panther or newer and don&apos;t want to install ImageMagick, there&apos;s also the sips <a href="http://www.apple.com/applescript/imageevents/">&#8220;Scriptable Image Processing System&#8221;</a> utility included with OS X.  The -m flag (which is documented in &#8220;sips -h&#8221; but not the man page) allows you to convert to a given profile.  (Apple calls this &#8220;matching&#8221; to a profile, which to my ear doesn&apos;t suggest the lossy color conversion process.)  This keeps many but not all of the <span class="caps">EXIF </span>tags from a photo.  On my test photo it retained 88 out of 145 <span class="caps">EXIF </span>tags found by exiftool.  I haven&apos;t analyzed the tags it dropped, so you&apos;ll have to check it out yourself if you decide to go this route.<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.n8gray.org%2Fblog%2F2006%2F04%2F27%2Fcommand-line-color-matching-on-os-x%2F&amp;linkname=Command-Line%20Color%20Matching%20on%20OS%20X"><img src="http://www.n8gray.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.n8gray.org/blog/2006/04/27/command-line-color-matching-on-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Appscript:  Palatable Apple Scripting in Python</title>
		<link>http://www.n8gray.org/blog/2004/11/17/appscript-palatable-apple-scripting-in-python/</link>
		<comments>http://www.n8gray.org/blog/2004/11/17/appscript-palatable-apple-scripting-in-python/#comments</comments>
		<pubDate>Wed, 17 Nov 2004 13:36:00 +0000</pubDate>
		<dc:creator>n8</dc:creator>
				<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.n8gray.org/sandbox/wordpress/?p=69</guid>
		<description><![CDATA[AppleScript is remarkable for being perhaps the worst programming language in modern history that has managed nonetheless to reach a wide audience.  This unlikely success can be attributed to the fact that application scripting is fantastically useful and, when it comes to application scripting on the Mac platform, AppleScript has always been pretty much [...]]]></description>
			<content:encoded><![CDATA[<p>AppleScript is remarkable for being perhaps the worst programming language in modern history that has managed nonetheless to reach a wide audience.  This unlikely success can be attributed to the fact that application scripting is fantastically useful and, when it comes to application scripting on the Mac platform, AppleScript has always been pretty much the only game in town.  

<p>All that is on the brink of changing, however, thanks to Hamish Sanderson&apos;s <a href="http://freespace.virgin.net/hamish.sanderson/appscript.html">appscript</a> project.  Appscript allows you to do OS X application scripting with <a href="http://www.python.org">Python</a> in a fairly natural, object-oriented fashion.  For example, to get a list of the file locations for all photos in the current iPhoto album you can write this Python code:


<pre>files = app(&quot;iPhoto.app&quot;).current_album.photos.image_path.get()</pre>


<p>To find out what properties an album has you can write:</p>


<pre>app(&quot;iPhoto.app&quot;).current_album.help()</pre>



<p>So why is this important?  To be sure, it has been possible, if awkward, to do app scripting in Python for quite a while now using <code>gensuitemodule</code> and friends.  The problem is that this process was incredibly awkward and error-prone, and it required a fairly deep understanding of how AppleScript works internally.  It&apos;s also true that there have been other scripting languages besides AppleScript for Mac <span class="caps">OS, </span>but they have all been languages with little or no application outside of that niche.  Many of them were commercial, which badly impeded widespread acceptance.  With appscript, we Mac folks get the ability to script our apps in a clean, general-purpose, open-source language without the need to learn too many details about Apple Events and such.

<p>Another reason this matters is that OS X is increasingly attracting Linux users who have become tired of recompiling kernels and having flaky hardware support.  These people have lots of experience scripting in various languages like Bash and Python.  They&apos;re not likely to pick up AppleScript since it&apos;s such a crappy language and has no application besides OS X app scripting.  If they can accomplish the same things in Python, however, then the floodgate opens for all sorts of cool hacks and scripts.  

<p>As a demonstration of what I&apos;m talking about, I offer <a href="/blog/2004/11/16#iphoto2album">iphoto2album</a>, a script that takes the current iPhoto album and adds it to a photo album made by <a href="http://marginalhacks.com/Hacks/album/">Album</a>.  It requires working installations of iPhoto, appscript, and album, of course.  You&apos;ll probably need to tweak a couple of parameters at the top of the scripts, but there&apos;s nothing too tricky.  Granted, this is probably too tricky for the average Mac user, but it&apos;s a start.

<p>Speaking of Linux to OS X converts, I was pinged recently by <a href="http://www.advogato.org/person/titus/">Titus Brown</a>, who was one of the first folks I know to make the jump.  He recently established a blog and appears to be updating it frequently, unlike myself.  I&apos;m lucky to push out one post a month &#8212; he seems to be doing them daily.  If his first few posts are anything to go by, the blog should be titled &#8220;How to Win Friends and Influence People in the Bioinformatics Software Industry.&#8221;  <span class="caps">BTW,</span> Titus is one of the few people I know who actually <em>writes</em> code as often as he <em>talks</em> about writing code, so he truly has a leg to stand on when he tells you your software sucks ass.  <img src='http://www.n8gray.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   Thankfully, my code is generally too short to suck ass.  It would have to suck ankle or kneecap or something.<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.n8gray.org%2Fblog%2F2004%2F11%2F17%2Fappscript-palatable-apple-scripting-in-python%2F&amp;linkname=Appscript%3A%20%20Palatable%20Apple%20Scripting%20in%20Python"><img src="http://www.n8gray.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.n8gray.org/blog/2004/11/17/appscript-palatable-apple-scripting-in-python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New: iphoto2album</title>
		<link>http://www.n8gray.org/blog/2004/11/17/new-iphoto2album/</link>
		<comments>http://www.n8gray.org/blog/2004/11/17/new-iphoto2album/#comments</comments>
		<pubDate>Wed, 17 Nov 2004 07:11:00 +0000</pubDate>
		<dc:creator>n8</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[appscript]]></category>
		<category><![CDATA[Photography]]></category>

		<guid isPermaLink="false">http://www.n8gray.org/sandbox/wordpress/?p=71</guid>
		<description><![CDATA[This is a script that exports an iPhoto album to an Album album.  It&apos;s my first attempt at application scripting using Hamish Sanderson&apos;s appscript.  You need a working installation of appscript, Album, and iPhoto, and you need an existing Album album.  See the comments at the top of the script for installation [...]]]></description>
			<content:encoded><![CDATA[<p>This is a script that exports an iPhoto album to an <a href="http://marginalhacks.com/Hacks/album/">Album</a> album.  It&apos;s my first attempt at application scripting using Hamish Sanderson&apos;s <a href="http://freespace.virgin.net/hamish.sanderson/appscript.html">appscript</a>.  You need a working installation of appscript, Album, and iPhoto, and you need an existing Album album.  See the comments at the top of the script for installation instructions.

<p>Caveat Emptor: It would be nice if this was a <em>bit</em> more friendly and didn&apos;t involve 
<ul>
    <li>installing so many dependencies
    <li>editing a text file
    <li>reading and understanding words connected into sentences
    <li>several other things the average Mac user can&apos;t be bothered to do
</ul>

<p>If I get good feedback and feel motivated maybe I&apos;ll package the whole thing into an app using <a href="http://sveinbjorn.vefsyn.is/platypus">Platypus</a>.

<p>Get it <a href="/code/files/iphoto2album">here</a>.<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.n8gray.org%2Fblog%2F2004%2F11%2F17%2Fnew-iphoto2album%2F&amp;linkname=New%3A%20iphoto2album"><img src="http://www.n8gray.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.n8gray.org/blog/2004/11/17/new-iphoto2album/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

