<?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>Smiths R Us &#187; Technology</title>
	<atom:link href="http://smithsrus.com/category/technology/feed/" rel="self" type="application/rss+xml" />
	<link>http://smithsrus.com</link>
	<description>Technology, home automation, usability, and whatever else amuses me.</description>
	<lastBuildDate>Fri, 27 Jan 2012 17:28:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>iOS 5 Safari Now Has Native HTML5 Date and Time Pickers</title>
		<link>http://smithsrus.com/ios-5-safari-now-has-native-html5-date-and-time-pickers/</link>
		<comments>http://smithsrus.com/ios-5-safari-now-has-native-html5-date-and-time-pickers/#comments</comments>
		<pubDate>Sat, 05 Nov 2011 21:01:45 +0000</pubDate>
		<dc:creator>Doug Smith</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Safari]]></category>
		<category><![CDATA[WebKit]]></category>

		<guid isPermaLink="false">http://smithsrus.com/?p=201</guid>
		<description><![CDATA[This falls under the category of sometimes it&#8217;s the little mundane things that can get me excited… I&#8217;ve been wanting mobile Safari to have native date pickers ever since I started creating Web apps for iPhone. Every time I dealt with date fields I had to create pickers with javascript that were just not as [...]]]></description>
			<content:encoded><![CDATA[<p>This falls under the category of sometimes it&#8217;s the little mundane things that can get me excited…</p>
<p>I&#8217;ve been wanting mobile Safari to have native date pickers ever since I started creating Web apps for iPhone. Every time I dealt with date fields I had to create pickers with javascript that were just not as good as those for real iPhone apps. I had been checking to see if native pickers were included in each iOS release but forgot about checking iOS 5 until now.<span id="more-201"></span></p>
<p>Here are some samples.</p>

<a href='http://smithsrus.com/ios-5-safari-now-has-native-html5-date-and-time-pickers/img_0299/' title='iOS 5 Safari HTML5 native date picker'><img width="150" height="150" src="http://smithsrus.com/wp-content/uploads/2011/11/IMG_0299-150x150.png" class="attachment-thumbnail" alt="iOS 5 Safari HTML5 native date picker" title="iOS 5 Safari HTML5 native date picker" /></a>
<a href='http://smithsrus.com/ios-5-safari-now-has-native-html5-date-and-time-pickers/img_0302/' title='iOS 5 Safari HTML5 native date and time picker'><img width="150" height="150" src="http://smithsrus.com/wp-content/uploads/2011/11/IMG_0302-150x150.png" class="attachment-thumbnail" alt="iOS 5 Safari HTML5 native date and time picker" title="iOS 5 Safari HTML5 native date and time picker" /></a>
<a href='http://smithsrus.com/ios-5-safari-now-has-native-html5-date-and-time-pickers/img_0300/' title='iOS 5 Safari HTML5 native month picker'><img width="150" height="150" src="http://smithsrus.com/wp-content/uploads/2011/11/IMG_0300-150x150.png" class="attachment-thumbnail" alt="iOS 5 Safari HTML5 native month picker" title="iOS 5 Safari HTML5 native month picker" /></a>

]]></content:encoded>
			<wfw:commentRss>http://smithsrus.com/ios-5-safari-now-has-native-html5-date-and-time-pickers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I Don&#8217;t Want a Verizon iPhone</title>
		<link>http://smithsrus.com/i-dont-want-a-verizon-iphone/</link>
		<comments>http://smithsrus.com/i-dont-want-a-verizon-iphone/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 16:58:20 +0000</pubDate>
		<dc:creator>Doug Smith</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[rumors]]></category>
		<category><![CDATA[Verizon]]></category>

		<guid isPermaLink="false">http://smithsrus.com/?p=175</guid>
		<description><![CDATA[Rumors of a Verizon iPhone have been circulating for years. Even though none have materialized, the news ticker on our TV today showed that the mainstream media has picked up the topic&#8230;again. This new surge of rumors seems no more likely than previous batches. I suspect they are fueled only by wishful thinking, which I [...]]]></description>
			<content:encoded><![CDATA[<p>Rumors of a Verizon iPhone have been circulating for years. Even though none have materialized, the news ticker on our TV today showed that the mainstream media has picked up the topic&#8230;again. This new surge of rumors seems no more likely than previous batches. I suspect they are fueled only by wishful thinking, which I can&#8217;t completely relate to.</p>
<p>I may be in the minority, but I don&#8217;t want a Verizon iPhone.<span id="more-175"></span></p>
<p>You see, I cheered when Apple chose AT&amp;T for the iPhone. I had been a Verizon customer and was happy to leave. Why? Let&#8217;s not forget some of these things:</p>
<ul>
<li>Verizon is the company that has <a href="http://www.eweek.com/c/a/Mobile-and-Wireless/Verizon-Wireless-Users-Sue-Over-Disabled-Bluetooth-Features/">removed Bluetooth features</a> from phones. <a href="http://www.askdavetaylor.com/why_doesnt_my_motorola_razr_have_obex_with_bluetooth.html">They disabled syncing and file transfer</a> so they could limit photo transfers to over the air where they could charge for each one.</li>
<li>Verizon also <a href="http://jkontherun.com/2009/07/17/verizon-please-stop-disabling-gps-in-smartphones-on-your-network/">blocked GPS features</a> so 3rd party software or Web apps couldn&#8217;t compete with their VZ Navigator and monthly fee. Although they were forced to enable GPS features through a<a href="http://www.cyberlawonline.com/cyberlawg/general-interest/suit-challenges-verizon-on-blackberry-gps.html"> class action lawsuit</a>, the important <a href="http://www.precentral.net/3rd-party-apps-cannot-access-agps-verizon-palm-pre-pixi-plus">aGPS data still remains locked</a> for all but VZ Navigator.</li>
<li>Verizon has <a href="http://www.urbanmusic2000.com/forum/general-music-news/22539-i-tried-using-ventones-but-verizon-blocks-ventone-ringtones-there-another-way-i-can-recieve-my-ringtones.html">blocked transferring ringtones</a> to your phone unless you purchased them through Verizon.</li>
<li>Verizon is the company famous for lousy customer service and quietly <a href="http://www.howtomobile.com/verizon-news/verizon-wireless-to-allow-users-to-change-plan-with-no-contract-extension/">renewing your contract</a> every time you make any little change to your service.</li>
<li>Verizon&#8217;s CEO is known for making <a href="http://www.engadget.com/2005/04/17/verizon-ceo-thinks-its-unreasonable-to-expect-your-cellphone/">boneheaded and customer-unfriendly statements</a>.</li>
<li>Verizon <a href="http://cybernetnews.com/verizon-admits-that-their-unlimited-data-plan-is-limited-to-5gb-per-month/">advertised unlimited data plans with no disclaimer</a> then canceled customer&#8217;s accounts without warning for using too much. They were eventually <a href="http://www.fiercebroadbandwireless.com/story/verizon-settles-lawsuit-over-unlimited-data-plans/2007-10-25">forced to add an asterisk and fine print</a> to their advertising.</li>
<li>Verizon has a habit of <a href="http://www.readwriteweb.com/archives/verizon_customers_-_just_say_no.php">selling personal customer data</a>.</li>
<li>Verizon has <a href="http://www.bulldogsandbroncos.com/2009/05/10/rip-off-artists-verizon-wireless/">charged customers usage minutes</a> for browsing Verizon&#8217;s own <em>Get it Now</em> store.</li>
</ul>
<p>Now I don&#8217;t know how many of these practices still stand today, but they were all in place when I got my iPhone. I always felt like I was fighting my service provider to do the things that seemed natural to do.</p>
<p>Apple changed the game with the iPhone by requiring these kinds of features to just work as part of the package. Photos, ringtones, Web surfing, GPS, music, movies, etc. all work and sync as you would expect. AT&amp;T was willing to play by the new rules and that has spurred the innovation we have today.</p>
<p>Sure, AT&amp;T has experienced growing pains with the influx of iPhone customers. Any network would.</p>
<p>Cell coverage really depends on where you happen to be. It sometimes flip flops between which carrier has the best signal in particular locations, but most of the time I notice all carriers having some of the same trouble spots.</p>
<p>We do have a few areas around here where Verizon coverage is marginally better. But my AT&amp;T coverage is good too and has improved immensely over the last couple years even though I&#8217;m not in a major city. We have 3G all over the area and I know AT&amp;T has added towers, replaced antennas, and tuned signal directions. I&#8217;ve also seen them change to lower frequencies in some areas to better penetrate through trees and buildings.</p>
<p>The bottom line is that my iPhone has changed the way I do things for the better and the Apple / AT&amp;T partnership has contributed to that experience. My shiny new iPhone 4 is scheduled to arrive tomorrow. It requires renewing my contract for a couple more years and I&#8217;m happy to do so.</p>
]]></content:encoded>
			<wfw:commentRss>http://smithsrus.com/i-dont-want-a-verizon-iphone/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Gravatar, AppleScript, and the OS X Address Book Revisited</title>
		<link>http://smithsrus.com/gravatar-applescript-and-the-os-x-address-book-revisited/</link>
		<comments>http://smithsrus.com/gravatar-applescript-and-the-os-x-address-book-revisited/#comments</comments>
		<pubDate>Tue, 11 May 2010 00:19:56 +0000</pubDate>
		<dc:creator>Doug Smith</dc:creator>
				<category><![CDATA[applescript]]></category>
		<category><![CDATA[Gravatar]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://smithsrus.com/?p=160</guid>
		<description><![CDATA[A while back I did a series of posts (part 1, part 2, part 3, and part 4) on using Gravatars in AppleScript to update pictures in your Mac Address Book. Those address pictures then sync to your iPhone, iPod Touch, or iPad. I&#8217;ve learned a few things since then, plus the Gravatar service has [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I did a series of posts (<a href="http://smithsrus.com/gravatar-applescript-and-address-book-pictures/">part 1</a>, <a href="http://smithsrus.com/setting-an-address-book-picture-with-applescript/">part 2</a>, <a href="http://smithsrus.com/detecting-when-gravatar-has-no-image/">part 3</a>, and <a href="http://smithsrus.com/filling-mac-address-book-pictures-with-gravatars/">part 4</a>) on using Gravatars in AppleScript to update pictures in your Mac Address Book. Those address pictures then sync to your iPhone, iPod Touch, or iPad.</p>
<p>I&#8217;ve learned a few things since then, plus the Gravatar service has a new option that removes the need for a workaround I had to come up with. So it&#8217;s time for an update to my now obsolete posts.<span id="more-160"></span></p>
<h3>Reference Implementation One: Gravatar to an AppleScript Variable</h3>
<p>The most common use case of Gravatar in AppleScript is probably to grab someone&#8217;s Gravatar image based on an e-mail address then pass it into some other application. Many Mac applications pass image data internally as a TIFF. So here&#8217;s an example of looking up a Gravatar and storing the raw picture data in a variable.</p>
<p>Here&#8217;s the script: (<a href="applescript://com.apple.scripteditor?action=new&#038;script=--%20Download%20a%20Gravatar%20image%20for%20the%20given%20e-mail%20address%20and%20store%20in%20a%20variable%20as%20a%20TIFF%20image.%20Display%20error%20if%20a%20matching%20gravatar%20doesn%27t%20exist.%0D--%20Released%20under%20GPL.%0D--%20by%20Doug%20Smith%2C%20http%3A//smithsrus.com%0D%0D--%20The%20e-mail%20address%20to%20look%20up.%0Dset%20email%20to%20%22someone%40somewhere.com%22%0D%0D--%20Calculate%20an%20MD5%20for%20the%20e-mail%20address.%0Dset%20md5_email%20to%20do%20shell%20script%20%22md5%20-q%20-s%20%60echo%20%22%20%26%20email%20%26%20%22%20%7C%20tr%20%27%5B%3Aupper%3A%5D%27%20%27%5B%3Alower%3A%5D%27%60%22%0D%0D--%20Construct%20the%20Gravatar%20URL.%0Dset%20grav_url%20to%20quoted%20form%20of%20%28%22http%3A//gravatar.com/avatar/%22%20%26%20md5_email%20%26%20%22%3Fd%3D404%22%20as%20text%29%0D%0D--%20Get%20the%20Gravatar%20image%20with%20a%20timeout%20of%2010%20seconds.%0Dtry%0D%09set%20pict_data%20to%20do%20shell%20script%20%22curl%20-fsS%20%22%20%26%20grav_url%20%26%20%22%20-m%2010%22%20as%20TIFF%20picture%20without%20altering%20line%20endings%0D%09tell%20me%20to%20display%20dialog%20%22Yes%2C%20we%20have%20a%20matching%20Gravatar.%22%20buttons%20%7B%22Okay%22%7D%20default%20button%201%0Don%20error%0D%09tell%20me%20to%20display%20dialog%20%22Sorry%2C%20there%20was%20no%20matching%20Gravatar.%22%20buttons%20%7B%22Cancel%22%7D%20default%20button%201%0Dend%20try%0D">Open in Script Editor</a>)</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
</pre></td><td class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- Download a Gravatar image for the given e-mail address and store in a variable as a TIFF image. Display error if a matching gravatar doesn't exist.</span>
<span style="color: #808080; font-style: italic;">-- Released under GPL.</span>
<span style="color: #808080; font-style: italic;">-- by Doug Smith, http://smithsrus.com</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- The e-mail address to look up.</span>
<span style="color: #ff0033; font-weight: bold;">set</span> email <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;someone@somewhere.com&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Calculate an MD5 for the e-mail address.</span>
<span style="color: #ff0033; font-weight: bold;">set</span> md5_email <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;md5 -q -s `echo &quot;</span> <span style="color: #000000;">&amp;</span> email <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; | tr '[:upper:]' '[:lower:]'`&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Construct the Gravatar URL.</span>
<span style="color: #ff0033; font-weight: bold;">set</span> grav_url <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #000000;">&#40;</span><span style="color: #009900;">&quot;http://gravatar.com/avatar/&quot;</span> <span style="color: #000000;">&amp;</span> md5_email <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;?d=404&quot;</span> <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">text</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Get the Gravatar image with a timeout of 10 seconds.</span>
<span style="color: #ff0033; font-weight: bold;">try</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> pict_data <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;curl -fsS &quot;</span> <span style="color: #000000;">&amp;</span> grav_url <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; -m 10&quot;</span> <span style="color: #ff0033;">as</span> TIFF picture <span style="color: #ff0033; font-weight: bold;">without</span> altering line endings
	<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">me</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">display dialog</span> <span style="color: #009900;">&quot;Yes, we have a matching Gravatar.&quot;</span> <span style="color: #0066ff;">buttons</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;Okay&quot;</span><span style="color: #000000;">&#125;</span> default button <span style="color: #000000;">1</span>
<span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #ff0033; font-weight: bold;">error</span>
	<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">me</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">display dialog</span> <span style="color: #009900;">&quot;Sorry, there was no matching Gravatar.&quot;</span> <span style="color: #0066ff;">buttons</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;Cancel&quot;</span><span style="color: #000000;">&#125;</span> default button <span style="color: #000000;">1</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span></pre></td></tr></table></div>

<p>As you can see, we end up calling some shell commands because Applescript doesn&#8217;t have all of the needed functionality. That&#8217;s no big deal because it only uses capabilities built into OS X and should work on any Mac.</p>
<h3>Reference Implementation Two: Gravatar to a File</h3>
<p>There may be some cases where it&#8217;s more useful to download the Gravatar image to a file for later use instead of loading it into a variable. With just a few modifications we can simply save the jpeg file as served up by Gravatar.</p>
<p>Here&#8217;s the script: (<a href="applescript://com.apple.scripteditor?action=new&#038;script=--%20Download%20a%20Gravatar%20image%20for%20the%20given%20e-mail%20address%20and%20store%20in%20a%20temporary%20file.%20Display%20error%20if%20a%20matching%20gravatar%20doesn%27t%20exist.%0D--%20Released%20under%20GPL.%0D--%20by%20Doug%20Smith%2C%20http%3A//smithsrus.com%0D%0D--%20The%20e-mail%20address%20to%20look%20up.%0Dset%20email%20to%20%22doug%40smithsrus.com%22%0D%0D--%20Calculate%20an%20MD5%20for%20the%20e-mail%20address.%0Dset%20md5_email%20to%20do%20shell%20script%20%22md5%20-q%20-s%20%60echo%20%22%20%26%20email%20%26%20%22%20%7C%20tr%20%27%5B%3Aupper%3A%5D%27%20%27%5B%3Alower%3A%5D%27%60%22%0D%0D--%20Construct%20the%20Gravatar%20URL.%0Dset%20grav_url%20to%20quoted%20form%20of%20%28%22http%3A//gravatar.com/avatar/%22%20%26%20md5_email%20%26%20%22%3Fd%3D404%22%20as%20text%29%0D%0D--%20Make%20a%20file%20name%20in%20which%20to%20temporarily%20save%20the%20Gravatar.%0Dset%20grav_file%20to%20%28path%20to%20temporary%20items%29%20%26%20%22gravatar%22%20%26%20md5_email%20%26%20%22.jpg%22%20as%20text%0Dset%20grav_POSIX_file%20to%20quoted%20form%20of%20POSIX%20path%20of%20grav_file%0D%0D--%20Download%20the%20Gravatar%20image%20to%20the%20temporary%20file%20with%20a%20timeout%20of%2010%20seconds.%0Dtry%0D%09do%20shell%20script%20%22curl%20-fsS%20%22%20%26%20grav_url%20%26%20%22%20-m%2010%20-o%20%22%20%26%20grav_POSIX_file%0D%09tell%20me%20to%20display%20dialog%20%22Yes%2C%20we%20have%20a%20matching%20Gravatar%20downloaded%20to%20%22%20%26%20grav_POSIX_file%20%26%20%22.%22%20buttons%20%7B%22Delete%20the%20File%22%7D%20default%20button%201%0D%09%0D%09tell%20application%20%22System%20Events%22%0D%09%09delete%20file%20grav_file%0D%09end%20tell%0Don%20error%0D%09tell%20me%20to%20display%20dialog%20%22Sorry%2C%20there%20was%20no%20matching%20Gravatar.%22%20buttons%20%7B%22Cancel%22%7D%20default%20button%201%0Dend%20try%0D%0D">Open in Script Editor</a>)</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
</pre></td><td class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- Download a Gravatar image for the given e-mail address and store in a temporary file. Display error if a matching gravatar doesn't exist.</span>
<span style="color: #808080; font-style: italic;">-- Released under GPL.</span>
<span style="color: #808080; font-style: italic;">-- by Doug Smith, http://smithsrus.com</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- The e-mail address to look up.</span>
<span style="color: #ff0033; font-weight: bold;">set</span> email <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;someone@somewhere.com&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Calculate an MD5 for the e-mail address.</span>
<span style="color: #ff0033; font-weight: bold;">set</span> md5_email <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;md5 -q -s `echo &quot;</span> <span style="color: #000000;">&amp;</span> email <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; | tr '[:upper:]' '[:lower:]'`&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Construct the Gravatar URL.</span>
<span style="color: #ff0033; font-weight: bold;">set</span> grav_url <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #000000;">&#40;</span><span style="color: #009900;">&quot;http://gravatar.com/avatar/&quot;</span> <span style="color: #000000;">&amp;</span> md5_email <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;?d=404&quot;</span> <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">text</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Make a file name in which to temporarily save the Gravatar.</span>
<span style="color: #ff0033; font-weight: bold;">set</span> grav_file <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">path to</span> temporary <span style="color: #0066ff;">items</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;gravatar&quot;</span> <span style="color: #000000;">&amp;</span> md5_email <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;.jpg&quot;</span> <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">text</span>
<span style="color: #ff0033; font-weight: bold;">set</span> grav_POSIX_file <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">POSIX path</span> <span style="color: #ff0033; font-weight: bold;">of</span> grav_file
&nbsp;
<span style="color: #808080; font-style: italic;">-- Download the Gravatar image to the temporary file with a timeout of 10 seconds.</span>
<span style="color: #ff0033; font-weight: bold;">try</span>
	<span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;curl -fsS &quot;</span> <span style="color: #000000;">&amp;</span> grav_url <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; -m 10 -o &quot;</span> <span style="color: #000000;">&amp;</span> grav_POSIX_file
	<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">me</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">display dialog</span> <span style="color: #009900;">&quot;Yes, we have a matching Gravatar downloaded to &quot;</span> <span style="color: #000000;">&amp;</span> grav_POSIX_file <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;.&quot;</span> <span style="color: #0066ff;">buttons</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;Delete the File&quot;</span><span style="color: #000000;">&#125;</span> default button <span style="color: #000000;">1</span>
	<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: #0066ff;">delete</span> <span style="color: #0066ff;">file</span> grav_file
	<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
<span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #ff0033; font-weight: bold;">error</span>
	<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">me</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">display dialog</span> <span style="color: #009900;">&quot;Sorry, there was no matching Gravatar.&quot;</span> <span style="color: #0066ff;">buttons</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;Cancel&quot;</span><span style="color: #000000;">&#125;</span> default button <span style="color: #000000;">1</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span></pre></td></tr></table></div>

<h3>Filling Address Book with Gravatars</h3>
<p>My goal for starting this whole project was to be able to populate my Mac Address Book with Gravatar pictures. Those then get automatically synced to my iPhone, which is really nice when receiving calls. A hat tip to <a href="http://momo.brauchtman.net/2009/03/missing-link-update-contact-image-in-macs-address-book-using-gravatar/">Moritz Haarmann for his Gravatar Address Book plugin</a>, which is what started me thinking about this in the first place. His plugin only works on one record at a time so I wanted to expand the concept to mass update selected records or the whole Address Book.</p>
<p>Rather than list the full script here, you can just <a href="http://smithsrus.com/dl/Gravatar-to-Address-Book-Pictures.zip">download the application</a>. You can open it in Script Editor if you want to see how it works. Be sure to back up your Address Book file, just in case. And if you experience errors or odd behavior, try quitting and relaunching Address Book, which often fixes little problems with it.</p>
<p>Be sure to let me know how you like it and if it works well for you. It would be interesting to know what percentage of addresses everyone is finding have Gravatars available now. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://smithsrus.com/gravatar-applescript-and-the-os-x-address-book-revisited/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Computer Repair Tools from the Kitchen</title>
		<link>http://smithsrus.com/computer-repair-tools-from-the-kitchen/</link>
		<comments>http://smithsrus.com/computer-repair-tools-from-the-kitchen/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 02:50:58 +0000</pubDate>
		<dc:creator>Doug Smith</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://smithsrus.com/?p=31</guid>
		<description><![CDATA[I was doing some repair work on a laptop computer today and realized I had not yet shared one of my most significant homemade tools for this kind of work. It&#8217;s simply an ice cube tray with each cube numbered in permanent marker. I put screws and other small parts in the tray as I [...]]]></description>
			<content:encoded><![CDATA[<p>I was doing some repair work on a laptop computer today and realized I had not yet shared one of my most significant homemade tools for this kind of work. It&#8217;s simply an ice cube tray with each cube numbered in permanent marker.</p>
<p><img src="http://smithsrus.com/wp-content/uploads/2010/03/ice-cube-tray-parts-holder.jpg" alt="Computer parts in an ice cube tray" title="Computer parts in an ice cube tray" width="480" height="288" class="aligncenter size-full wp-image-167" /></p>
<p>I put screws and other small parts in the tray as I disassemble each section of the computer. If I&#8217;m following a numbered repair guide I try to match the cube number to each step. Otherwise, I just fill the cubes in numerical order as it makes sense. Reassembly is a snap and there&#8217;s no losing or mixing up those tiny screws.</p>
<p>Oh, and while I&#8217;m snatching kitchen items to use as tools, cookie sheets make great parts trays for longer-term projects. The whole project can be shelved to get it out of the way and then easily resumed without parts getting misplaced. </p>
]]></content:encoded>
			<wfw:commentRss>http://smithsrus.com/computer-repair-tools-from-the-kitchen/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Loading WordPress&#8217; Thickbox Only When Needed</title>
		<link>http://smithsrus.com/loading-wordpress-thickbox-only-when-needed/</link>
		<comments>http://smithsrus.com/loading-wordpress-thickbox-only-when-needed/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 16:24:15 +0000</pubDate>
		<dc:creator>Doug Smith</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://smithsrus.com/?p=165</guid>
		<description><![CDATA[I like to use Thickbox on my site to display images and videos in overlay windows. In WordPress, it&#8217;s easy enough to use wp_enqueue_script( ) and wp_enqueue_style() to load the built-in version of Thickbox. It automatically takes care of including jQuery, putting the css in the header, and the javascript in the footer. But there&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I like to use Thickbox on my site to display images and videos in overlay windows. In WordPress, it&#8217;s easy enough to use wp_enqueue_script( ) and wp_enqueue_style() to load the built-in version of Thickbox. It automatically takes care of including jQuery, putting the css in the header, and the javascript in the footer. </p>
<p>But there&#8217;s no need to have the bloat of Thickbox and jQuery loading on all pages when most of them don&#8217;t even use it. That&#8217;s why <a href="http://yoast.com/conditional-thickbox-loading/">Joost de Valk detailed a nice tip to only load thickbox when needed</a> by checking the page content for references to it. All it takes is a few lines of code in your functions.php file.</p>
<p>Unfortunately, you end up with some broken images because the built-in Thickbox defines their locations in thickbox.js as relative paths:<span id="more-165"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> tb_pathToImage <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;../wp-includes/js/thickbox/loadingAnimation.gif&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> tb_closeImage <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;../wp-includes/js/thickbox/tb-close.png&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Those paths get tacked onto the URL of whatever page you&#8217;re on, which results in an invalid URL and a couple 404 errors for each use. Now that&#8217;s not unique to Joost&#8217;s solution. It happens whenever Thickbox is loaded with wp_enqueue_script( ).</p>
<p>It can easily be fixed by adding a couple lines of javascript in the footer to redefine the image path variables. That&#8217;s as simple as a few more lines of code in your functions.php file. We&#8217;ll use Joost&#8217;s technique of only loading it when the page content requires it:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> thickbox_image_paths<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">;</span>
	wp_reset_query<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>is_singular<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_content</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'class=&quot;thickbox&quot;'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$thickbox_path</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'siteurl'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/wp-includes/js/thickbox/'</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;script type=<span style="color: #000099; font-weight: bold;">\&quot;</span>text/javascript<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;	var tb_pathToImage = <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">${thickbox_path}</span>loadingAnimation.gif<span style="color: #000099; font-weight: bold;">\&quot;</span>;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;	var tb_closeImage = <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">${thickbox_path}</span>tb-close.png<span style="color: #000099; font-weight: bold;">\&quot;</span>;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/script&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_footer'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'thickbox_image_paths'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>My theme uses multiple loops so I had to add the wp_reset_query() to be able to examine the original content. Otherwise it would be looking at the last post in my recent posts box and not see that Thickbox was used in the current content.</p>
<p>There you have it. A nice technique from Joost and a simple addition to complement it.</p>
]]></content:encoded>
			<wfw:commentRss>http://smithsrus.com/loading-wordpress-thickbox-only-when-needed/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>GPS Geolocation in Safari on iPhone OS 3.0</title>
		<link>http://smithsrus.com/gps-geolocation-in-safari-on-iphone-os-3-0/</link>
		<comments>http://smithsrus.com/gps-geolocation-in-safari-on-iphone-os-3-0/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 02:00:59 +0000</pubDate>
		<dc:creator>Doug Smith</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[GPS]]></category>

		<guid isPermaLink="false">http://smithsrus.com/?p=157</guid>
		<description><![CDATA[I just updated my iPhone to the shiny new OS 3.0. Apple did a great job addressing a few shortcomings and adding new features. Others have already told about the common features so I won&#8217;t rehash them here. But let me tell you about my favorite new feature: Safari can now get your GPS location [...]]]></description>
			<content:encoded><![CDATA[<p>I just updated my iPhone to the shiny new OS 3.0. Apple did a great job addressing a few shortcomings and adding new features. Others have already <a href="http://www.ismashphone.com/2009/06/how_to_use_best_40_features_of_iphone_3.html">told about the common features</a> so I won&#8217;t rehash them here.</p>
<p>But let me tell you about my favorite new feature: Safari can now get your GPS location via javascript!<span id="more-157"></span> This is usually referred to as <em>geolocation</em>. You can easily grab the current location or get periodic updates.</p>
<p>Okay, so I&#8217;m excited over what may seem like an obscure geeky feature, but I think it&#8217;s a big deal. </p>
<h3>Why GPS in Safari is a Big Deal</h3>
<ol>
<li>
<p><strong>Location aware Web pages:</strong> Have you ever gone to a company&#8217;s Web site to find their nearest location? You usually have to type in your zip code. But what if you&#8217;re traveling and don&#8217;t know your zip code? Safari knowing your location solves that problem.
</li>
<li>
<p><strong>Location aware Web applications:</strong> It&#8217;s fairly easy to create Web content looks and behaves like an iPhone application. Now those can take advantage of location information.
<p>For example, I&#8217;ve been working with a company on an iPhone Web application that interacts with their internal customer database. Field reps can now easily find customers within a certain radius of the rep&#8217;s current location who meet various other criteria.</p>
</li>
</ol>
<h3>Web Geolocation Privacy and Standards</h3>
<p>Don&#8217;t worry, all of this is built with good privacy controls. You are asked permission before your location data is revealed to a site. For convenience, it stops asking about a particular site after you have approved it a few times.</p>
<p>These location features are based on the upcoming <a href="http://dev.w3.org/geo/api/spec-source.html">Geolocation API Specification</a>. Because it&#8217;s not just a proprietary Safari thing it should get widespread adoption. In fact, it&#8217;s already built into the latest Firefox 3.5 beta.</p>
<h3>Web Geolocation Sample Code</h3>
<p>The specifications do a good job of explaining the parts so no need to go over all of that. However, it&#8217;s worth pointing out how to check and see if geolocation features are available or not and take appropriate action. For example, you may only want to show GPS options if it can actually be used. This simple snippet will do the job.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>navigator.<span style="color: #660066;">geolocation</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  
	<span style="color: #009966; font-style: italic;">/* Code if geolocation is available. */</span>  
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>  
	<span style="color: #009966; font-style: italic;">/* Code if geolocation is not available */</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Let&#8217;s put it all together in a simple Web page that displays all of the geolocation variables for your current location. The code is below or you can try my <a href="http://smithsrus.com/geo.html">geolocation test page</a> from your iPhone.</p>
<p>(Yes, you&#8217;ll probably want to use modern DOM techniques for a real project. The purpose of this is just to show a simple working example.)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;!</span>DOCTYPE html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html lang<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;en&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;content-type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/html; charset=utf-8&quot;</span><span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>meta <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;viewport&quot;</span> content<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;&quot;</span> <span style="color: #339933;">/&gt;</span>
		<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>Geolocation Test<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
&nbsp;
		<span style="color: #339933;">&lt;</span>script language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;javascript&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
			<span style="color: #003366; font-weight: bold;">function</span> getLocation<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #006600; font-style: italic;">// Get location no more than 10 minutes old. 600000 ms = 10 minutes.</span>
				navigator.<span style="color: #660066;">geolocation</span>.<span style="color: #660066;">getCurrentPosition</span><span style="color: #009900;">&#40;</span>showLocation<span style="color: #339933;">,</span> showError<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>enableHighAccuracy<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>maximumAge<span style="color: #339933;">:</span><span style="color: #CC0000;">600000</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #003366; font-weight: bold;">function</span> showError<span style="color: #009900;">&#40;</span>error<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>error.<span style="color: #660066;">code</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' '</span> <span style="color: #339933;">+</span> error.<span style="color: #660066;">message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #003366; font-weight: bold;">function</span> showLocation<span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				geoinfo.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'&lt;p&gt;Latitude: '</span> <span style="color: #339933;">+</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">latitude</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/p&gt;'</span> 
				<span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;p&gt;Longitude: '</span> <span style="color: #339933;">+</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">longitude</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/p&gt;'</span> 
				<span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;p&gt;Accuracy: '</span> <span style="color: #339933;">+</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">accuracy</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/p&gt;'</span> 
				<span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;p&gt;Altitude: '</span> <span style="color: #339933;">+</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">altitude</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/p&gt;'</span> 
				<span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;p&gt;Altitude accuracy: '</span> <span style="color: #339933;">+</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">altitudeAccuracy</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/p&gt;'</span> 
				<span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;p&gt;Speed: '</span> <span style="color: #339933;">+</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">speed</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/p&gt;'</span> 
				<span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;p&gt;Heading: '</span> <span style="color: #339933;">+</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">heading</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>script language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;javascript&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>	
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>navigator.<span style="color: #660066;">geolocation</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  
				document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;p&gt;&lt;input type=&quot;button&quot; onclick=&quot;getLocation()&quot; value=&quot;Show Geolocation Information&quot; /&gt;&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>  
				document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;p&gt;Sorry, your device or browser software does not appear to support geolocation services.&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
			<span style="color: #009900;">&#125;</span>  
		<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
&nbsp;
		<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;geoinfo&quot;</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></div></div>

<p>I can&#8217;t wait to see some of the great things others will create by combining Web sites with location. And it will only get better as more devices become location aware. Be sure to let me know of good location-aware sites and web apps you run across.</p>
<p>Now go create something cool!</p>
]]></content:encoded>
			<wfw:commentRss>http://smithsrus.com/gps-geolocation-in-safari-on-iphone-os-3-0/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Filling Mac Address Book Pictures with Gravatars</title>
		<link>http://smithsrus.com/filling-mac-address-book-pictures-with-gravatars/</link>
		<comments>http://smithsrus.com/filling-mac-address-book-pictures-with-gravatars/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 15:09:04 +0000</pubDate>
		<dc:creator>Doug Smith</dc:creator>
				<category><![CDATA[Gravatar]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[avatar]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Macintosh]]></category>

		<guid isPermaLink="false">http://smithsrus.com/?p=151</guid>
		<description><![CDATA[[This information in this post is out of date. Please see Gravatar, AppleScript, and the OS X Address Book Revisited for more current information.] This is a multi-part tutorial series on using Gravatar from AppleScript to update your Mac Address Book pictures automatically. These pictures then sync to your iPhone for Gravatar goodness on the [...]]]></description>
			<content:encoded><![CDATA[<p><em>[This information in this post is out of date. Please see <a href="http://smithsrus.com/gravatar-applescript-and-the-os-x-address-book-revisited/">Gravatar, AppleScript, and the OS X Address Book Revisited</a> for more current information.]</em><br />
<hr />
<p>This is a multi-part tutorial series on using <a href="http://gravatar.com/">Gravatar</a> from <a href="http://www.apple.com/applescript/">AppleScript</a> to update your Mac Address Book pictures automatically. These pictures then sync to your iPhone for Gravatar goodness on the go.</p>
<p>I&#8217;ve had some AppleScripts to work with Gravatars and Address Book hanging around in rough form for quite a while. But I was recently prompted to clean them up and write these tutorials when <a href="http://ma.tt/2009/03/gravatar-in-gmail/">Matt Mullenweg posted about Gravatar on his blog</a> saying that &#8220;we need a better way to get Gravatars into your Apple address book / iPhone.&#8221; I hope that the documentation and tools from this project will be used for other creative Gravatar integration projects.</p>
<p>We&#8217;re about to put all of what we learned in <a href="http://smithsrus.com/gravatar-applescript-and-address-book-pictures/">part 1</a>, <a href="http://smithsrus.com/setting-an-address-book-picture-with-applescript/">part 2</a>, and <a href="http://smithsrus.com/detecting-when-gravatar-has-no-image/">part 3</a> together to make our working script.<span id="more-151"></span> Be sure to check out the previous parts for the details of how it all works.</p>
<p>Here is the process the script will be doing:</p>
<ol>
<li>Get a list of only the selected contacts from Address Book. This way we can control which contacts get their pictures updated if we don&#8217;t want them all.</li>
<li>Ask the user if we should overwrite any existing pictures or skip those contacts.</li>
<li>Step through each of those contacts and get all of the e-mail addresses associated with each.</li>
<li>Step through each e-mail address and download its Gravatar to a temporary file. If there is more than one address with a Gravatar we&#8217;ll keep it simple and just let it set each one in turn and we&#8217;ll end up with last one found. This could be improved in the future to favor a particular one if needed.</li>
<li>Update the Address Book picture, delete the temporary file, then repeat the process with the next contact.</li>
</ol>
<p>Here&#8217;s the script: (<a href="applescript://com.apple.scripteditor?action=new&#038;script=--%20Set%20selected%20Address%20Book%20contact%20pictures%20from%20Gravatar.%0D--%20Released%20under%20GPL.%0D--%20by%20Doug%20Smith%2C%20http%3A//smithsrus.com%0D%0D%0D--%20Grab%20the%20selected%20records%20and%20see%20how%20many%20there%20are.%0Dtell%20application%20%22Address%20Book%22%0D%09set%20selected_contacts%20to%20selection%0D%09set%20count_selected%20to%20number%20of%20items%20in%20selected_contacts%0D%09%0D%09--%20Bail%20out%20if%20there%20are%20no%20records%20selected.%20Otherwise%20ask%20about%20how%20to%20deal%20%0D%09--%20with%20contacts%20having%20existing%20pictures.%0D%09if%20count_selected%20%3C%201%20then%0D%09%09tell%20me%20to%20display%20dialog%20%22You%20must%20first%20select%20some%20Address%20Book%20contacts.%22%20buttons%20%7B%22Cancel%22%7D%20default%20button%201%20cancel%20button%201%0D%09else%0D%09%09if%20count_selected%20%3D%201%20then%0D%09%09%09set%20plural%20to%20%22%22%0D%09%09else%0D%09%09%09set%20plural%20to%20%22s%22%0D%09%09end%20if%0D%09%09tell%20me%20to%20set%20user_result%20to%20display%20dialog%20%22We%27re%20about%20to%20try%20updating%20%22%20%26%20count_selected%20%26%20%22%20selected%20Address%20Book%20contact%20picture%22%20%26%20plural%20%26%20%22%20from%20Gravatar.%20Would%20you%20like%20to%20overwrite%20existing%20pictures%20or%20skip%20those%20contacts%3F%22%20buttons%20%7B%22Cancel%22%2C%20%22Overwrite%20Existing%22%2C%20%22Skip%20Existing%22%7D%20cancel%20button%201%20default%20button%201%20with%20icon%20caution%0D%09%09set%20overwrite%20to%20%28button%20returned%20of%20user_result%20contains%20%22Overwrite%22%29%0D%09end%20if%0D%09%0D%09--%20Step%20through%20each%20contact%20and%20find%20Gravatars.%0D%09with%20timeout%20of%20600%20seconds%0D%09%09repeat%20with%20one_contact%20in%20selected_contacts%0D%09%09%09if%20not%20%28%28image%20of%20one_contact%20exists%29%20and%20not%20overwrite%29%20then%0D%09%09%09%09%0D%09%09%09%09--%20Step%20through%20the%20contact%27s%20e-mail%20addresses.%0D%09%09%09%09set%20all_emails%20to%20emails%20of%20one_contact%0D%09%09%09%09repeat%20with%20one_email_record%20in%20all_emails%0D%09%09%09%09%09set%20one_email_address%20to%20value%20of%20one_email_record%0D%09%09%09%09%09%0D%09%09%09%09%09set%20grav_file%20to%20%28my%20get_gravatar%28my%20trim_email%28one_email_address%29%29%29%0D%09%09%09%09%09%0D%09%09%09%09%09--%20If%20we%20have%20a%20Gravatar%20image%20add%20it%20to%20the%20contact.%0D%09%09%09%09%09if%20grav_file%20is%20not%20%22%22%20then%0D%09%09%09%09%09%09set%20image%20of%20one_contact%20to%20my%20get_pict_data%28grav_file%29%0D%09%09%09%09%09end%20if%0D%09%09%09%09end%20repeat%0D%09%09%09end%20if%0D%09%09end%20repeat%0D%09end%20timeout%0D%09tell%20me%20to%20display%20dialog%20%22Done.%20You%20may%20need%20to%20select%20a%20different%20record%20to%20force%20Address%20Book%20to%20refresh%20the%20screen%20before%20changes%20show.%22%20buttons%20%7B%22Okay%22%7D%20default%20button%201%0Dend%20tell%0D%0D%0D--%20Trim%20junk%20off%20the%20end%20of%20the%20e-mail%20address%20field.%20Assume%20space%20separated.%0Don%20trim_email%28email_address%29%0D%09set%20AppleScript%27s%20text%20item%20delimiters%20to%20%22%20%22%0D%09return%20item%201%20of%20email_address%0Dend%20trim_email%0D%0D%0D--%20Look%20up%20a%20Gravatar%20from%20an%20e-mail%20address%20and%20save%20to%20a%20file.%0Don%20get_gravatar%28email_address%29%0D%09--%20Calculate%20an%20MD5%20for%20the%20e-mail%20address.%0D%09set%20md5_email%20to%20do%20shell%20script%20%22md5%20-q%20-s%20%60echo%20%22%20%26%20email_address%20%26%20%22%20%7C%20tr%20%27%5B%3Aupper%3A%5D%27%20%27%5B%3Alower%3A%5D%27%60%22%0D%09%0D%09--%20Construct%20the%20Gravatar%20URL.%20Max%20Address%20Book%20picture%20size%20stored%20is%20218%20pixels.%0D%09set%20grav_url%20to%20quoted%20form%20of%20%28%22http%3A//gravatar.com/avatar/%22%20%26%20md5_email%20%26%20%22%3Fs%3D218%26d%3D%22%20%26%20%22%2522%2522%22%20as%20text%29%0D%09%0D%09--%20Make%20a%20file%20name%20in%20which%20to%20temporarily%20save%20the%20Gravatar.%0D%09set%20grav_file%20to%20%28path%20to%20temporary%20items%29%20%26%20%22gravatar%22%20%26%20md5_email%20%26%20%22.jpg%22%20as%20text%0D%09set%20grav_POSIX_file%20to%20quoted%20form%20of%20POSIX%20path%20of%20grav_file%0D%09%0D%09--%20Download%20the%20Gravatar%20image%20to%20the%20temporary%20file%20with%20a%20timeout%20of%2010%20seconds.%0D%09do%20shell%20script%20%22curl%20%22%20%26%20grav_url%20%26%20%22%20-m%2010%20-o%20%22%20%26%20grav_POSIX_file%0D%09%0D%09tell%20application%20%22System%20Events%22%0D%09%09if%20exists%20file%20grav_file%20then%0D%09%09%09return%20grav_file%0D%09%09else%0D%09%09%09return%20%22%22%0D%09%09end%20if%0D%09end%20tell%0Dend%20get_gravatar%0D%0D--%20Read%20the%20picture%20data%20into%20a%20variable%20in%20TIFF%20format%20then%20delete%20the%20file.%0Don%20get_pict_data%28grav_file%29%0D%09tell%20application%20%22System%20Events%22%0D%09%09set%20file_ref%20to%20open%20for%20access%20grav_file%0D%09%09set%20pict_data%20to%20read%20file_ref%20as%20%22TIFF%22%0D%09%09close%20access%20file_ref%0D%09%09%0D%09%09delete%20file%20grav_file%0D%09%09return%20pict_data%0D%09end%20tell%0Dend%20get_pict_data">Open in Script Editor</a>)</p>

<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- Set selected Address Book contact pictures from Gravatar.</span>
<span style="color: #808080; font-style: italic;">-- Released under GPL.</span>
<span style="color: #808080; font-style: italic;">-- by Doug Smith, http://smithsrus.com</span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;">-- Grab the selected records and see how many there are.</span>
<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Address Book&quot;</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> selected_contacts <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">selection</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> count_selected <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">number</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">in</span> selected_contacts
&nbsp;
	<span style="color: #808080; font-style: italic;">-- Bail out if there are no records selected. Otherwise ask about how to deal </span>
	<span style="color: #808080; font-style: italic;">-- with contacts having existing pictures.</span>
	<span style="color: #ff0033; font-weight: bold;">if</span> count_selected <span style="color: #000000;">&lt;</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">then</span>
		<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">me</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">display dialog</span> <span style="color: #009900;">&quot;You must first select some Address Book contacts.&quot;</span> <span style="color: #0066ff;">buttons</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;Cancel&quot;</span><span style="color: #000000;">&#125;</span> default button <span style="color: #000000;">1</span> cancel button <span style="color: #000000;">1</span>
	<span style="color: #ff0033; font-weight: bold;">else</span>
		<span style="color: #ff0033; font-weight: bold;">if</span> count_selected <span style="color: #000000;">=</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">then</span>
			<span style="color: #ff0033; font-weight: bold;">set</span> plural <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span>
		<span style="color: #ff0033; font-weight: bold;">else</span>
			<span style="color: #ff0033; font-weight: bold;">set</span> plural <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;s&quot;</span>
		<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;">tell</span> <span style="color: #0066ff;">me</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033; font-weight: bold;">set</span> user_result <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">display dialog</span> <span style="color: #009900;">&quot;We're about to try updating &quot;</span> <span style="color: #000000;">&amp;</span> count_selected <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; selected Address Book contact picture&quot;</span> <span style="color: #000000;">&amp;</span> plural <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; from Gravatar. Would you like to overwrite existing pictures or skip those contacts?&quot;</span> <span style="color: #0066ff;">buttons</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;Cancel&quot;</span>, <span style="color: #009900;">&quot;Overwrite Existing&quot;</span>, <span style="color: #009900;">&quot;Skip Existing&quot;</span><span style="color: #000000;">&#125;</span> cancel button <span style="color: #000000;">1</span> default button <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">with</span> icon caution
		<span style="color: #ff0033; font-weight: bold;">set</span> overwrite <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>button returned <span style="color: #ff0033; font-weight: bold;">of</span> user_result <span style="color: #ff0033;">contains</span> <span style="color: #009900;">&quot;Overwrite&quot;</span><span style="color: #000000;">&#41;</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;">-- Step through each contact and find Gravatars.</span>
	<span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #ff0033; font-weight: bold;">timeout</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #000000;">600</span> seconds
		<span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> one_contact <span style="color: #ff0033; font-weight: bold;">in</span> selected_contacts
			<span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #ff0033;">not</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>image <span style="color: #ff0033; font-weight: bold;">of</span> one_contact <span style="color: #0066ff;">exists</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033;">and</span> <span style="color: #ff0033;">not</span> overwrite<span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
&nbsp;
				<span style="color: #808080; font-style: italic;">-- Step through the contact's e-mail addresses.</span>
				<span style="color: #ff0033; font-weight: bold;">set</span> all_emails <span style="color: #ff0033; font-weight: bold;">to</span> emails <span style="color: #ff0033; font-weight: bold;">of</span> one_contact
				<span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> one_email_record <span style="color: #ff0033; font-weight: bold;">in</span> all_emails
					<span style="color: #ff0033; font-weight: bold;">set</span> one_email_address <span style="color: #ff0033; font-weight: bold;">to</span> value <span style="color: #ff0033; font-weight: bold;">of</span> one_email_record
&nbsp;
					<span style="color: #ff0033; font-weight: bold;">set</span> grav_file <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span><span style="color: #ff0033; font-weight: bold;">my</span> get_gravatar<span style="color: #000000;">&#40;</span><span style="color: #ff0033; font-weight: bold;">my</span> trim_email<span style="color: #000000;">&#40;</span>one_email_address<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
&nbsp;
					<span style="color: #808080; font-style: italic;">-- If we have a Gravatar image add it to the contact.</span>
					<span style="color: #ff0033; font-weight: bold;">if</span> grav_file <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">not</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> image <span style="color: #ff0033; font-weight: bold;">of</span> one_contact <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033; font-weight: bold;">my</span> get_pict_data<span style="color: #000000;">&#40;</span>grav_file<span style="color: #000000;">&#41;</span>
					<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;">repeat</span>
			<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;">repeat</span>
	<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">timeout</span>
	<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">me</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">display dialog</span> <span style="color: #009900;">&quot;Done. You may need to select a different record to force Address Book to refresh the screen before changes show.&quot;</span> <span style="color: #0066ff;">buttons</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;Okay&quot;</span><span style="color: #000000;">&#125;</span> default button <span style="color: #000000;">1</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;">-- Trim junk off the end of the e-mail address field. Assume space separated.</span>
<span style="color: #ff0033; font-weight: bold;">on</span> trim_email<span style="color: #000000;">&#40;</span>email_address<span style="color: #000000;">&#41;</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> AppleScript<span style="">'</span>s <span style="color: #0066ff;">text</span> <span style="color: #0066ff;">item</span> <span style="color: #0066ff;">delimiters</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot; &quot;</span>
	<span style="color: #ff0033; font-weight: bold;">return</span> <span style="color: #0066ff;">item</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">of</span> email_address
<span style="color: #ff0033; font-weight: bold;">end</span> trim_email
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;">-- Look up a Gravatar from an e-mail address and save to a file.</span>
<span style="color: #ff0033; font-weight: bold;">on</span> get_gravatar<span style="color: #000000;">&#40;</span>email_address<span style="color: #000000;">&#41;</span>
	<span style="color: #808080; font-style: italic;">-- Calculate an MD5 for the e-mail address.</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> md5_email <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;md5 -q -s `echo &quot;</span> <span style="color: #000000;">&amp;</span> email_address <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; | tr '[:upper:]' '[:lower:]'`&quot;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">-- Construct the Gravatar URL. Max Address Book picture size stored is 218 pixels.</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> grav_url <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #000000;">&#40;</span><span style="color: #009900;">&quot;http://gravatar.com/avatar/&quot;</span> <span style="color: #000000;">&amp;</span> md5_email <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;?s=218&amp;d=&quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;%22%22&quot;</span> <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">text</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">-- Make a file name in which to temporarily save the Gravatar.</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> grav_file <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">path to</span> temporary <span style="color: #0066ff;">items</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;gravatar&quot;</span> <span style="color: #000000;">&amp;</span> md5_email <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;.jpg&quot;</span> <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">text</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> grav_POSIX_file <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">POSIX path</span> <span style="color: #ff0033; font-weight: bold;">of</span> grav_file
&nbsp;
	<span style="color: #808080; font-style: italic;">-- Download the Gravatar image to the temporary file with a timeout of 10 seconds.</span>
	<span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;curl &quot;</span> <span style="color: #000000;">&amp;</span> grav_url <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; -m 10 -o &quot;</span> <span style="color: #000000;">&amp;</span> grav_POSIX_file
&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;">if</span> <span style="color: #0066ff;">exists</span> <span style="color: #0066ff;">file</span> grav_file <span style="color: #ff0033; font-weight: bold;">then</span>
			<span style="color: #ff0033; font-weight: bold;">return</span> grav_file
		<span style="color: #ff0033; font-weight: bold;">else</span>
			<span style="color: #ff0033; font-weight: bold;">return</span> <span style="color: #009900;">&quot;&quot;</span>
		<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;">tell</span>
<span style="color: #ff0033; font-weight: bold;">end</span> get_gravatar
&nbsp;
<span style="color: #808080; font-style: italic;">-- Read the picture data into a variable in TIFF format then delete the file.</span>
<span style="color: #ff0033; font-weight: bold;">on</span> get_pict_data<span style="color: #000000;">&#40;</span>grav_file<span style="color: #000000;">&#41;</span>
	<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;">set</span> file_ref <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">open</span> for access grav_file
		<span style="color: #ff0033; font-weight: bold;">set</span> pict_data <span style="color: #ff0033; font-weight: bold;">to</span> read file_ref <span style="color: #ff0033;">as</span> <span style="color: #009900;">&quot;TIFF&quot;</span>
		<span style="color: #0066ff;">close</span> access file_ref
&nbsp;
		<span style="color: #0066ff;">delete</span> <span style="color: #0066ff;">file</span> grav_file
		<span style="color: #ff0033; font-weight: bold;">return</span> pict_data
	<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
<span style="color: #ff0033; font-weight: bold;">end</span> get_pict_data</pre></div></div>

<p>There you have it. I have some ideas to take it further but I&#8217;ll let everyone test what we have and offer feedback before continuing. I&#8217;ll also make an easier to use application download for everyone once we&#8217;ve done enough testing to work out the kinks.</p>
]]></content:encoded>
			<wfw:commentRss>http://smithsrus.com/filling-mac-address-book-pictures-with-gravatars/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Detecting When Gravatar Has No Image</title>
		<link>http://smithsrus.com/detecting-when-gravatar-has-no-image/</link>
		<comments>http://smithsrus.com/detecting-when-gravatar-has-no-image/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 16:31:51 +0000</pubDate>
		<dc:creator>Doug Smith</dc:creator>
				<category><![CDATA[Gravatar]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[address book]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Macintosh]]></category>
		<category><![CDATA[photo]]></category>

		<guid isPermaLink="false">http://smithsrus.com/?p=149</guid>
		<description><![CDATA[[This information in this post is out of date. Please see Gravatar, AppleScript, and the OS X Address Book Revisited for more current information.] We&#8217;re on our way to building an AppleScript to update all of the contacts in your Mac Address Book with pictures from the Gravatar service. This is part 3 of the [...]]]></description>
			<content:encoded><![CDATA[<p><em>[This information in this post is out of date. Please see <a href="http://smithsrus.com/gravatar-applescript-and-the-os-x-address-book-revisited/">Gravatar, AppleScript, and the OS X Address Book Revisited</a> for more current information.]</em><br />
<hr />
<p>We&#8217;re on our way to building an <a href="http://www.apple.com/applescript/">AppleScript</a> to update all of the contacts in your Mac Address Book with pictures from the <a href="http://gravatar.com/">Gravatar</a> service. This is part 3 of the series.</p>
<p>Part 1, <a href="http://smithsrus.com/gravatar-applescript-and-address-book-pictures/">Gravatar, AppleScript, and Address Book Pictures</a>, introduced the topic and ended with a short AppleScript to construct a Gravatar URL given an e-mail address.</p>
<p>Then in part 2, <a href="http://smithsrus.com/setting-an-address-book-picture-with-applescript/">Setting an Address Book Picture with AppleScript</a>, we built a script showing how to successfully set a contact photo in Address Book.</p>
<p>Now we need to detect when the Gravatar service does not have an image on file for a given e-mail address.<span id="more-149"></span> The problem is that Gravatar does one of several things when it doesn&#8217;t have a matching image: return a default image, return an image you specify, or generate an image in one of several styles. But in every case it returns an image.</p>
<p>This is all well and good if you&#8217;re displaying Gravatars on a blog comments page. The Gravatar URL ends up inside an img tag and this keeps it dead simple. It&#8217;s also nice for everyone to get some kind of avatar even if they haven&#8217;t created one.</p>
<p>But for our purposes we don&#8217;t need a default image that ends up being attached to a contact. Not only does it clutter our contacts, but it would make it more difficult if we later wanted our script to only update contacts with no existing picture and leave the others alone.</p>
<p>Detecting a no match condition would also be useful in a WordPress plugin even if a default image was used. For example, I&#8217;ve always wanted to display some sort of indicator and a link to Gravatar for those who don&#8217;t have a Gravatar yet. If we can detect that a default image was used then we can set a CSS class on the image or do other creative things.</p>
<p>So how do we tell if there is no image match? It&#8217;s simple with a little undocumented trick in the Gravatar URL.</p>
<p>There is a d= parameter where we can specify a default image to return when there is no match. If we set that to null by using two empty URL encoded quotes then instead of a default image we get nothing. For example:</p>
<p><code></p>
<p>http://www.gravatar.com/avatar/1bc47906dcb8f3661bae9a8448e49a8a?d=%22%22</p>
<p></code></p>
<p>For our Address Book script we need to save the image to a file anyway so we just check for the existence of the file or a zero size. We can skip that entry or take other action if there is nothing there.</p>
<p>In the case of a WordPress plugin it might be less convenient because we may have to hit the Gravatar servers twice; once to check for a no match condition, then again to get the image with whatever default we actually want. Of course, if we use a local default file then it would still only be one call to the Gravatar service but that rules out using one of the cool generated defaults.</p>
<p>(If any of the Gravatar folks are listening, it would be great to have an option in the URL that means I&#8217;m using this for further processing and not in an img tag then also pass back some sort of status telling if the image is a default.)</p>
<p>Here&#8217;s a demonstration AppleScript that makes use of the above technique to download a Gravatar for a given e-mail address and take action only if there was a matched image: (<a href="applescript://com.apple.scripteditor?action=new&#038;script=--%20Download%20a%20Gravatar%20image%20and%20see%20if%20it%27s%20a%20match%20or%20default.%0D--%20Released%20under%20GPL.%0D--%20by%20Doug%20Smith%2C%20http%3A//smithsrus.com%0D%0D--%20The%20e-mail%20address%20to%20look%20up.%0Dset%20email%20to%20%22someone%40somewhere.com%22%0D%0D--%20Calculate%20an%20MD5%20for%20the%20e-mail%20address.%0Dset%20md5_email%20to%20do%20shell%20script%20%22md5%20-q%20-s%20%60echo%20%22%20%26%20email%20%26%20%22%20%7C%20tr%20%27%5B%3Aupper%3A%5D%27%20%27%5B%3Alower%3A%5D%27%60%22%0D%0D--%20Construct%20the%20Gravatar%20URL.%0Dset%20grav_url%20to%20quoted%20form%20of%20%28%22http%3A//gravatar.com/avatar/%22%20%26%20md5_email%20%26%20%22%3Fd%3D%22%20%26%20%22%2522%2522%22%20as%20text%29%0D%0D--%20Make%20a%20file%20name%20in%20which%20to%20temporarily%20save%20the%20Gravatar.%0Dset%20grav_file%20to%20%28path%20to%20temporary%20items%29%20%26%20%22gravatar%22%20%26%20md5_email%20%26%20%22.jpg%22%20as%20text%0Dset%20grav_POSIX_file%20to%20quoted%20form%20of%20POSIX%20path%20of%20grav_file%0D%0D--%20Download%20the%20Gravatar%20image%20to%20the%20temporary%20file%20with%20a%20timeout%20of%2010%20seconds.%0Ddo%20shell%20script%20%22curl%20%22%20%26%20grav_url%20%26%20%22%20-m%2010%20-o%20%22%20%26%20grav_POSIX_file%0D%0Dtell%20application%20%22System%20Events%22%0D%09if%20exists%20file%20grav_file%20then%0D%09%09tell%20me%20to%20display%20dialog%20%22Yes%2C%20we%20have%20a%20matching%20Gravatar%20downloaded%20to%20%22%20%26%20grav_POSIX_file%20%26%20%22.%22%20buttons%20%7B%22Okay%22%7D%20default%20button%201%0D%09%09delete%20file%20grav_file%0D%09else%0D%09%09tell%20me%20to%20display%20dialog%20%22Sorry%2C%20there%20was%20no%20matching%20Gravatar.%22%20buttons%20%7B%22Okay%22%7D%20default%20button%201%0D%09end%20if%0Dend%20tell%0D">Open in Script Editor</a>)</p>
<p><ins datetime="2009-03-25T17:21:43+00:00">(Updated with a small bug fix on 03/25/2009.)</ins><br />
<ins datetime="2009-04-23T13:56:48+00:00">(Updated on 04/23/2009 to remove my testing e-mail address and display the downloaded file path.)</ins></p>

<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- Download a Gravatar image and see if it's a match or default.</span>
<span style="color: #808080; font-style: italic;">-- Released under GPL.</span>
<span style="color: #808080; font-style: italic;">-- by Doug Smith, http://smithsrus.com</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- The e-mail address to look up.</span>
<span style="color: #ff0033; font-weight: bold;">set</span> email <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;someone@somewhere.com&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Calculate an MD5 for the e-mail address.</span>
<span style="color: #ff0033; font-weight: bold;">set</span> md5_email <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;md5 -q -s `echo &quot;</span> <span style="color: #000000;">&amp;</span> email <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; | tr '[:upper:]' '[:lower:]'`&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Construct the Gravatar URL.</span>
<span style="color: #ff0033; font-weight: bold;">set</span> grav_url <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #000000;">&#40;</span><span style="color: #009900;">&quot;http://gravatar.com/avatar/&quot;</span> <span style="color: #000000;">&amp;</span> md5_email <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;?d=&quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;%22%22&quot;</span> <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">text</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Make a file name in which to temporarily save the Gravatar.</span>
<span style="color: #ff0033; font-weight: bold;">set</span> grav_file <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">path to</span> temporary <span style="color: #0066ff;">items</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;gravatar&quot;</span> <span style="color: #000000;">&amp;</span> md5_email <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;.jpg&quot;</span> <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">text</span>
<span style="color: #ff0033; font-weight: bold;">set</span> grav_POSIX_file <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">POSIX path</span> <span style="color: #ff0033; font-weight: bold;">of</span> grav_file
&nbsp;
<span style="color: #808080; font-style: italic;">-- Download the Gravatar image to the temporary file with a timeout of 10 seconds.</span>
<span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;curl &quot;</span> <span style="color: #000000;">&amp;</span> grav_url <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; -m 10 -o &quot;</span> <span style="color: #000000;">&amp;</span> grav_POSIX_file
&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;">if</span> <span style="color: #0066ff;">exists</span> <span style="color: #0066ff;">file</span> grav_file <span style="color: #ff0033; font-weight: bold;">then</span>
		<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">me</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">display dialog</span> <span style="color: #009900;">&quot;Yes, we have a matching Gravatar downloaded to &quot;</span> <span style="color: #000000;">&amp;</span> grav_POSIX_file <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;.&quot;</span> <span style="color: #0066ff;">buttons</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;Okay&quot;</span><span style="color: #000000;">&#125;</span> default button <span style="color: #000000;">1</span>
		<span style="color: #0066ff;">delete</span> <span style="color: #0066ff;">file</span> grav_file
	<span style="color: #ff0033; font-weight: bold;">else</span>
		<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">me</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">display dialog</span> <span style="color: #009900;">&quot;Sorry, there was no matching Gravatar.&quot;</span> <span style="color: #0066ff;">buttons</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;Okay&quot;</span><span style="color: #000000;">&#125;</span> default button <span style="color: #000000;">1</span>
	<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;">tell</span></pre></div></div>

<p>Well, we&#8217;re almost to our goal of a <a href="http://smithsrus.com/filling-mac-address-book-pictures-with-gravatars/">script to automatically update all of our Address Book contacts with Gravatars</a>. I&#8217;ll put it all together next time in <a href="http://smithsrus.com/filling-mac-address-book-pictures-with-gravatars/">part 4</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://smithsrus.com/detecting-when-gravatar-has-no-image/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Setting an Address Book Picture with AppleScript</title>
		<link>http://smithsrus.com/setting-an-address-book-picture-with-applescript/</link>
		<comments>http://smithsrus.com/setting-an-address-book-picture-with-applescript/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 00:15:20 +0000</pubDate>
		<dc:creator>Doug Smith</dc:creator>
				<category><![CDATA[Gravatar]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[address book]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Macintosh]]></category>
		<category><![CDATA[photo]]></category>

		<guid isPermaLink="false">http://smithsrus.com/?p=148</guid>
		<description><![CDATA[[This information in this post is out of date. Please see Gravatar, AppleScript, and the OS X Address Book Revisited for more current information.] In part 1, Gravatar, AppleScript, and Address Book Pictures, we covered the basics of getting a Gravatar URL with AppleScript. The end goal is to automatically update all of our Address [...]]]></description>
			<content:encoded><![CDATA[<p><em>[This information in this post is out of date. Please see <a href="http://smithsrus.com/gravatar-applescript-and-the-os-x-address-book-revisited/">Gravatar, AppleScript, and the OS X Address Book Revisited</a> for more current information.]</em><br />
<hr />
<p>In part 1, <a href="http://smithsrus.com/gravatar-applescript-and-address-book-pictures/">Gravatar, AppleScript, and Address Book Pictures</a>, we covered the basics of getting a <a href="http://gravatar.com/">Gravatar</a> URL with <a href="http://www.apple.com/applescript/">AppleScript</a>. The end goal is to automatically update all of our Address Book pictures with Gravatars in one fell swoop.</p>
<p>There are a couple tricky things we need to solve to reach our goal. They aren&#8217;t difficult; just not well documented, if at all.</p>
<p>In this post I&#8217;ll show you how to update a contact picture with AppleScript.<span id="more-148"></span></p>
<p>Let&#8217;s get started.</p>
<p>We know from the Gravatar documentation that it returns images in jpeg format. Now according to the AppleScript dictionary for Address Book, the person class has an image element that is in TIFF format. So we&#8217;ll have to convert the image.</p>
<p>In addition, Address Book is very particular about how it gets an image. The only way I could make it work was to have the actual TIFF picture data loaded into a variable then set the contact&#8217;s picture to that. I couldn&#8217;t just refer to a file, even if it was already a TIFF.</p>
<p>Fortunately, there&#8217;s no need to go through a big conversion script or call on other applications. You can simply open a jpeg file from AppleScript and read the contents into a variable while coercing it to TIFF format.</p>
<p>Here is a demonstration script showing how it works: (<a href="applescript://com.apple.scripteditor?action=new&amp;script=--%20Set%20an%20Address%20Book%20contact%20photo%20from%20a%20jpeg%20file.%0D--%20Released%20under%20GPL.%0D--%20by%20Doug%20Smith%2C%20http%3A//smithsrus.com%0D--%0D--%20This%20is%20for%20demonstration%20purposes.%20It%20only%20works%20on%20the%20first%20selected%20%0D--%20contact%20in%20Address%20Book%20and%20contains%20little%20error%20checking.%20Note%20that%0D--%20the%20picture%20displayed%20will%20not%20change%20until%20you%20select%20a%20different%20record%0D--%20then%20come%20back%20to%20the%20original%20record%20so%20it%20can%20refresh.%0D%0Dtell%20application%20%22Address%20Book%22%0D%09set%20AB_contacts%20to%20selection%0D%09%0D%09if%20number%20of%20items%20in%20AB_contacts%20%3D%201%20then%0D%09%09set%20one_contact%20to%20item%201%20of%20AB_contacts%0D%09%09%0D%09%09set%20pict_file%20to%20choose%20file%20of%20type%20%22JPEG%22%20with%20prompt%20%22Choose%20a%20jpeg%20file%22%0D%09%09open%20for%20access%20pict_file%0D%09%09set%20pict_data%20to%20read%20pict_file%20as%20%22TIFF%22%0D%09%09close%20access%20pict_file%0D%09%09%0D%09%09set%20image%20of%20one_contact%20to%20pict_data%0D%09end%20if%0Dend%20tell%0D">Open in Script Editor</a>)</p>

<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- Set an Address Book contact photo from a jpeg file.</span>
<span style="color: #808080; font-style: italic;">-- Released under GPL.</span>
<span style="color: #808080; font-style: italic;">-- by Doug Smith, http://smithsrus.com</span>
<span style="color: #808080; font-style: italic;">--</span>
<span style="color: #808080; font-style: italic;">-- This is for demonstration purposes. It only works on the first selected</span>
<span style="color: #808080; font-style: italic;">-- contact in Address Book and contains little error checking. Note that</span>
<span style="color: #808080; font-style: italic;">-- the picture displayed will not change until you select a different record</span>
<span style="color: #808080; font-style: italic;">-- then come back to the original record so it can refresh.</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Address Book&quot;</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> AB_contacts <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">selection</span>
&nbsp;
	<span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #0066ff;">number</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">in</span> AB_contacts <span style="color: #000000;">=</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">then</span>
		<span style="color: #ff0033; font-weight: bold;">set</span> one_contact <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">item</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">of</span> AB_contacts
&nbsp;
		<span style="color: #ff0033; font-weight: bold;">set</span> pict_file <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">choose file</span> <span style="color: #ff0033; font-weight: bold;">of</span> type <span style="color: #009900;">&quot;JPEG&quot;</span> <span style="color: #ff0033; font-weight: bold;">with</span> prompt <span style="color: #009900;">&quot;Choose a jpeg file&quot;</span>
		<span style="color: #0066ff;">open</span> for access pict_file
		<span style="color: #ff0033; font-weight: bold;">set</span> pict_data <span style="color: #ff0033; font-weight: bold;">to</span> read pict_file <span style="color: #ff0033;">as</span> <span style="color: #009900;">&quot;TIFF&quot;</span>
		<span style="color: #0066ff;">close</span> access pict_file
&nbsp;
		<span style="color: #ff0033; font-weight: bold;">set</span> image <span style="color: #ff0033; font-weight: bold;">of</span> one_contact <span style="color: #ff0033; font-weight: bold;">to</span> pict_data
	<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;">tell</span></pre></div></div>

<p>It&#8217;s worth noting that my attempts to get the picture data into a variable Address Book accepted by means other than reading a file were not successful. For example, I tried using a shell call to curl to download a file and return the results to a variable. That would have been nice for our purpose of downloading a Gravatar image. If anyone has any further insight on that please let me know.</p>
<p>That&#8217;s all for this post. Stay tuned for part 3 when I&#8217;ll cover <a href="http://smithsrus.com/detecting-when-gravatar-has-no-image/">Detecting When Gravatar Has No Image to Match an E-mail Address</a>. Then in part 4 we&#8217;ll put it all together with a <a href="http://smithsrus.com/filling-mac-address-book-pictures-with-gravatars/">Script to Update Address Book Contacts with Gravatar Images</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://smithsrus.com/setting-an-address-book-picture-with-applescript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Gravatar, AppleScript, and Address Book Pictures</title>
		<link>http://smithsrus.com/gravatar-applescript-and-address-book-pictures/</link>
		<comments>http://smithsrus.com/gravatar-applescript-and-address-book-pictures/#comments</comments>
		<pubDate>Sat, 21 Mar 2009 22:46:36 +0000</pubDate>
		<dc:creator>Doug Smith</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[avatar]]></category>
		<category><![CDATA[Gravatar]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://smithsrus.com/?p=147</guid>
		<description><![CDATA[[This information in this post is out of date. Please see Gravatar, AppleScript, and the OS X Address Book Revisited for more current information.] I&#8217;ve always been a fan of adding photos to the people in my Mac Address Book application. It&#8217;s a nice personal touch when the photo appears on e-mail messages from people [...]]]></description>
			<content:encoded><![CDATA[<p><em>[This information in this post is out of date. Please see <a href="http://smithsrus.com/gravatar-applescript-and-the-os-x-address-book-revisited/">Gravatar, AppleScript, and the OS X Address Book Revisited</a> for more current information.]</em><br />
<hr />
<p>I&#8217;ve always been a fan of adding photos to the people in my Mac Address Book application. It&#8217;s a nice personal touch when the photo appears on e-mail messages from people I know. And now that I have an iPhone, those photos sync to the phone and show up in my contacts and when I get calls.</p>
<p>But wouldn&#8217;t it be nice if we could add photos to our contacts without doing them all manually? Well, that&#8217;s where <a href="http://gravatar.com">Gravatar</a> and a little AppleScript will do the job.<span id="more-147"></span></p>
<p>For those not familiar with Gravatar, it&#8217;s a free avatar service from the nice folks who make <a href="http://wordpress.org">WordPress</a>. You register your e-mail address with the service and upload an avatar picture to go with it. Your avatar then automatically shows up on all sorts of blogs and forums where you post or comment, and can be put to use for other services as well.</p>
<p>We should be able to use AppleScript to step through our contacts, grab the e-mail address, retrieve the Gravatar, and add the picture to the contact. The <a href="http://en.gravatar.com/site/implement">Gravatar implementor&#8217;s guide</a> has useage instructions and lots of examples, but nothing for AppleScript. So let&#8217;s start with an AppleScript in the same style as the other implementer&#8217;s guide examples. (I won&#8217;t be covering how Gravatars work since it is so well documented. See <a href="http://en.gravatar.com/site/implement/url">How the URL is constructed</a> for details.)</p>
<p>AppleScript doesn&#8217;t have built-in commands for calculating md5, converting text to lowercase, and url encoding, which we need. Instead of writing all of that code, we can cheat a little and call the equivalent commands from the OS X shell.</p>
<p>Here&#8217;s the basic process:</p>
<ol>
<li>Change the e-mail address to lowercase.</li>
<li>md5 encode the e-mail address.</li>
<li>url encode the default image URL.</li>
<li>Slap it all together to make a Gravatar image URL.</li>
</ol>
<p>And here is the script to do it: (<a href="applescript://com.apple.scripteditor?action=new&#038;script=--%20Make%20a%20Gravatar%20URL%20from%20an%20e-mail%20address.%0D--%20Released%20under%20GPL.%0D--%20by%20Doug%20Smith%2C%20http%3A//smithsrus.com%0D%0D--%20The%20e-mail%20address%20to%20look%20up.%0Dset%20email%20to%20%22someone%40somewhere.com%22%0D%0D--%20Set%20a%20few%20defaults.%0Dproperty%20grav_default%20%3A%20%22http%3A//somewhere.com/homestar.jpg%22%0Dproperty%20grav_size%20%3A%2040%0D%0D--%20Encode%20the%20elements%20as%20needed.%0Dset%20md5_email%20to%20do%20shell%20script%20%22md5%20-q%20-s%20%60echo%20%22%20%26%20email%20%26%20%22%20%7C%20tr%20%27%5B%3Aupper%3A%5D%27%20%27%5B%3Alower%3A%5D%27%60%22%0Dset%20encode_default%20to%20do%20shell%20script%20%22echo%20%22%20%26%20grav_default%20%26%20%22%20%7C%20perl%20-MURI%3A%3AEscape%20-lne%20%27print%20uri_escape%28%24_%29%27%22%0D%0D--%20Construct%20the%20Gravatar%20URL.%0Dset%20grav_url%20to%20%22http%3A//gravatar.com/avatar/%22%20%26%20md5_email%20%26%20%22%3Fd%3D%22%20%26%20encode_default%20%26%20%22%26s%3D%22%20%26%20grav_size%20as%20text%0D">Open in Script Editor</a>)</p>

<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- Make a Gravatar URL from an e-mail address.</span>
<span style="color: #808080; font-style: italic;">-- Released under GPL.</span>
<span style="color: #808080; font-style: italic;">-- by Doug Smith, http://smithsrus.com</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- The e-mail address to look up.</span>
<span style="color: #ff0033; font-weight: bold;">set</span> email <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;someone@somewhere.com&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Set a few defaults.</span>
<span style="color: #ff0033; font-weight: bold;">property</span> grav_default : <span style="color: #009900;">&quot;http://somewhere.com/homestar.jpg&quot;</span>
<span style="color: #ff0033; font-weight: bold;">property</span> grav_size : <span style="color: #000000;">40</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Encode the elements as needed.</span>
<span style="color: #ff0033; font-weight: bold;">set</span> md5_email <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;md5 -q -s `echo &quot;</span> <span style="color: #000000;">&amp;</span> email <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; | tr '[:upper:]' '[:lower:]'`&quot;</span>
<span style="color: #ff0033; font-weight: bold;">set</span> encode_default <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;echo &quot;</span> <span style="color: #000000;">&amp;</span> grav_default <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; | perl -MURI::Escape -lne 'print uri_escape($_)'&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Construct the Gravatar URL.</span>
<span style="color: #ff0033; font-weight: bold;">set</span> grav_url <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;http://gravatar.com/avatar/&quot;</span> <span style="color: #000000;">&amp;</span> md5_email <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;?d=&quot;</span> <span style="color: #000000;">&amp;</span> encode_default <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;&amp;s=&quot;</span> <span style="color: #000000;">&amp;</span> grav_size <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">text</span></pre></div></div>

<p>This is getting a bit long so I&#8217;m going to break it into multiple parts.</p>
<p><del datetime="2009-03-22T22:34:54+00:00">In part 2 I&#8217;ll cover how to set an Address Book picture from AppleScript and how to detect if Gravatar doesn&#8217;t have an image for an address instead of ending up with a default image we don&#8217;t want. Both of those are a little tricky so it will likely fill that post. Part 3 will put it all together to automatically update pictures for the whole address book.</del></p>
<p>I changed my mind and decided to make the parts into smaller posts covering some of the individual tasks. I&#8217;m hoping this will make it easier for others to find these solutions for use in their own projects.</p>
<p>Part 2: <a href="http://smithsrus.com/setting-an-address-book-picture-with-applescript/">Setting an Address Book Picture with AppleScript</a><br />
Part 3: <a href="http://smithsrus.com/detecting-when-gravatar-has-no-image/">Detecting When Gravatar Has No Image to Match an E-mail Address</a><br />
Part 4: Putting it all together with a <a href="http://smithsrus.com/filling-mac-address-book-pictures-with-gravatars/">Script to Update Address Book Contacts with Gravatar Images</a>.</p>
<p>I have some ideas to take it further that may end up in a couple more posts. Please stay tuned and let me know what you think. I&#8217;ll construct the remaining posts based on feedback.</p>
]]></content:encoded>
			<wfw:commentRss>http://smithsrus.com/gravatar-applescript-and-address-book-pictures/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

