<?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>A Tasty Pixel » Blog &#187; Workflow</title>
	<atom:link href="http://atastypixel.com/blog/tag/workflow/feed/" rel="self" type="application/rss+xml" />
	<link>http://atastypixel.com/blog</link>
	<description></description>
	<lastBuildDate>Mon, 19 Jul 2010 10:22:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>OS X service to filter selected text through a shell command</title>
		<link>http://atastypixel.com/blog/os-x-service-to-filter-selected-text-through-a-shell-command/</link>
		<comments>http://atastypixel.com/blog/os-x-service-to-filter-selected-text-through-a-shell-command/#comments</comments>
		<pubDate>Sun, 23 May 2010 13:50:07 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/os-x-service-to-filter-selected-text-through-a-shell-command/</guid>
		<description><![CDATA[The UNIX shell provides a host of extremely useful utilities for modifying text. This Automator service makes all of them available for filtering text in all OS X applications.]]></description>
			<content:encoded><![CDATA[<p>The UNIX shell provides a host of extremely useful utilities for modifying text. This OS X Automator service makes all of them available for filtering text in all OS X applications.</p>

<p>This can be handy for performing quick operations, like replacing text with regular expressions, sorting lists or swapping fields around.</p>

<p>When triggered, the service requests a command to use for filtering, then runs the command and replaces the selected text with the result.</p>

<p>Some sample operations:</p>

<ul>
<li>Sort lines alphabetically/numerically: <tt>sort</tt> or <tt>sort -n</tt></li>
<li>Change to lowercase: <tt>tr "[:upper:]" "[:lower:]"</tt></li>
<li>Replace a spelling mistake, taking care of case: <tt>sed -E 's/([tT])eh/\1he/g'</tt></li>
<li>Re-order elements in a tab- or comma-separated list: <tt>awk '{print $2 $1}'</tt> or <tt>awk -F, '{print $2 "," $1}'</tt>
</ul>

<p><img src="http://atastypixel.com/blog/wp-content/uploads/2010/05/filter-service.jpg" width="400" height="397" alt="Filter through Shell Command service" class="aligncenter" /></p>

<p>Put it in <code>Library/Services</code>, and it should appear in the &#8216;Services&#8217; menu.</p>

<p><a href="http://atastypixel.com/blog/wp-content/uploads/2010/05/Filter-through-Shell-Command.zip" title="Filter through Shell Command.zip">Filter through Shell Command.zip</a></p>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1913" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/os-x-service-to-filter-selected-text-through-a-shell-command/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>DIY Twitter image hosting</title>
		<link>http://atastypixel.com/blog/diy-twitter-image-hosting/</link>
		<comments>http://atastypixel.com/blog/diy-twitter-image-hosting/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 14:16:07 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/?p=1757</guid>
		<description><![CDATA[Twitter doesn&#8217;t yet come with its own inline image support, so we tend to be limited to using image hosting services, and linking to them with short URLs. So, services like Tweetpic host the image, and we direct traffic to them in return. Thinking it&#8217;s better to keep things in the family, and take better [...]]]></description>
			<content:encoded><![CDATA[<p>Twitter doesn&#8217;t yet come with its own inline image support, so we tend to be limited to using image hosting services, and linking to them with short URLs.  So, services like Tweetpic host the image, and we direct traffic to them in return.</p>

<p>Thinking it&#8217;s better to keep things in the family, and take better advantage of that traffic, I put together an image hosting setup of my own.  Now viewers come to my own site, instead of someone else&#8217;s!</p>

<p>It looks like <a href="http://twitter.com/ATastyPixel/status/7478572775">this</a></p>

<p>The setup consists of an Automator service, and some PHP smarts on the site.</p>

<p><img src="http://atastypixel.com/blog/wp-content/michaelangelo-images/c7c164a7e7460cdbb5c7fbdc86cd77bf.jpg" width="250" height="133" alt="Send Image to Image Hosting" class="alignright polaroid rotation" />Under Snow Leopard, I can right-click on an image in Finder, click &#8216;Send Image to Image Hosting&#8217;, type in a title,  then paste the URL that&#8217;s automatically been put onto my clipboard into a tweet.</p>

<p>Here&#8217;s how it works &#8211; this assumes a moderate level of understanding of PHP and assorted web administration.<span id="more-1757"></span>
<em>Update</em>: I couldn&#8217;t help myself; I made a <a href="http://atastypixel.com/blog/wordpress/plugins/twitter-image-host">WordPress plugin</a> for this, with some extra nice features.</p>

<h2>Presentation</h2>

<p>First, we need to put together a script that will display the image.  What&#8217;s more, it would be nice to give the image a title, and link it back to the Twitter account.</p>

<p>So, we&#8217;ll want a place to put images, and a way to store the corresponding title and account name.</p>

<p>I opted to store the latter in a file alongside the image called <code>(imagename).meta</code>.  I store the title, then a newline, then the Twitter account name.</p>

<p>Lets create <code>image.php</code> &#8212; it should take an <code>image name</code> parameter, excluding the file extension, and display the corresponding image, with any corresponding meta data.</p>

<p>Here&#8217;s a sample:</p>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$MEDIA_DIR</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;twitter-images&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get the image name, but avoid any path shenanigans by just grabbing the 'basename' of the file</span>
<span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Make sure it exists, or report a 404 error</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #000088;">$image</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #990000;">is_file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$MEDIA_DIR</span>/<span style="color: #006699; font-weight: bold;">$image</span>.jpg&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;404.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Grab the meta data</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$MEDIA_DIR</span>/<span style="color: #006699; font-weight: bold;">$image</span>.meta&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$title</span><span style="color: #339933;">,</span> <span style="color: #000088;">$source</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$MEDIA_DIR</span>/<span style="color: #006699; font-weight: bold;">$image</span>.meta&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Set a default title if we don't have any meta data</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #000088;">$title</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ucwords</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Include the page header, if you like</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;header.inc.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;div class=&quot;content&quot;&gt;
&nbsp;
    &lt;img src=&quot;/<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> MEDIA_DIR <span style="color: #000000; font-weight: bold;">?&gt;</span>/<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$image</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>.jpg&quot; alt=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$title</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; class=&quot;image&quot; /&gt;
&nbsp;
    &lt;h1&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$title</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h1&gt;
&nbsp;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$source</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
        &lt;p&gt;
            From &lt;a href=&quot;http://twitter.com/<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$source</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
                &lt;img src=&quot;/media/images/twitter.png&quot; width=&quot;14&quot; height=&quot;14&quot; alt=&quot;Follow us on Twitter!&quot;&gt;
                <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$source</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
            &lt;/a&gt;
        &lt;/p&gt;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;/div&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;footer.inc.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>


<p>Make sure it works by making a sample image called, say, <code>IMG.jpg</code>, and an accompanying metadata file, called <code>IMG.meta</code> with a title on the first line and a twitter account name on the second, and opening up <code>http://yoursite.com/image.php?name=IMG</code></p>

<p>Now, we want to keep URLs short, so they don&#8217;t take up too much valuable space in a tweet, so we need to use some tricks here.</p>

<p>We&#8217;ll set up a <code>.htaccess</code> file that uses <code>mod_rewrite</code> to keep the URL short.</p>

<p>Something like this should do the trick:</p>

<blockquote>
<pre>
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/([^/]+)$
RewriteCond %{DOCUMENT_ROOT}/twitter-images/%1.jpg -f
RewriteRule (.*) /image.php?name=$1 [L]
&lt;/IfModule&gt;
</pre>
</blockquote>

<p>Note on the fifth line we are checking inside our Twitter images folder &#8212; make sure that matches your storage path.</p>

<p>This will take any requests that:</p>

<ul>
<li>Are located in the web-root (<em>start with a slash, followed by anything but a slash until the end</em>)</li>
<li>Have a corresponding file within the directory we&#8217;ll store images in</li>
</ul>

<p>Then, it&#8217;ll rewrite the request silently to use <code>image.php</code>.</p>

<p>Save the <code>.htaccess</code> file, and open <code>http://yoursite.com/IMG</code>.  It should bring up the image, just as before.</p>

<p>Set up some CSS to make it look good, and you&#8217;re set.  Here&#8217;s mine:</p>


<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;">/* @group Twitter images */</span>
&nbsp;
<span style="color: #6666ff;">.twitter-image</span> <span style="color: #6666ff;">.content</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.twitter-image</span> <span style="color: #6666ff;">.content</span> img<span style="color: #6666ff;">.image</span> <span style="color: #00AA00;">&#123;</span>
	-moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
	-webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#f1f1f1</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#aaa</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span>  <span style="color: #933;">40px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">60px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.twitter-image</span> <span style="color: #6666ff;">.content</span> h1 <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">padding-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">60px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.twitter-image</span> <span style="color: #6666ff;">.content</span> p <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.twitter-image</span> <span style="color: #6666ff;">.content</span> a <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.twitter-image</span> <span style="color: #6666ff;">.content</span> a img <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #3333ff;">:text-</span>bottom<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* @end */</span></pre></div></div>


<h2>Automator</h2>

<p>Now, with the web side set up, we need to set up an easy way to send content there.</p>

<p>I opted for an Automator service, which uses <code>scp</code> to upload the content.  If your web host doesn&#8217;t provide for <code>scp</code>, you may want to use something else like <a href="http://www.ncftp.com/download/">ncftpput</a>, or even an Applescript-able application.  You&#8217;ll need to modify the Automator action&#8217;s shell script accordingly.</p>

<p>Here&#8217;s the Automator service I set up: <a href="http://atastypixel.com/blog/wp-content/uploads/2010/01/Send-Image-to-Image-Hosting.zip" title="Send Image to Image Hosting.zip">Send Image to Image Hosting.zip</a>.</p>

<p>For those interested, it contains the following shell script:</p>


<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">APPSUPPORT=~/&quot;Library/Application Support/Image Hosting&quot;
TMPDIR='/tmp/image-hosting.tmp'
DEST='me@mywebsite.com:www/mywebsite/twitter-images/'
URLPREFIX='http://mywebsite.com/'
UPLOADRETRIES=3
# GROWL=&quot;/usr/local/bin/growlnotify&quot; # Uncomment this if you have Growl and growlnotify
&nbsp;
[ ! -e &quot;$APPSUPPORT&quot; ] &amp;&amp; mkdir &quot;$APPSUPPORT&quot;
&nbsp;
for f in &quot;$@&quot;
do
  if [ ! -e &quot;$f&quot; ]; then
    osascript -e 'tell application &quot;Finder&quot;' -e 'activate' -e 'display dialog &quot;Input file '&quot;$f&quot;' does not exist&quot; with title &quot;Image Hosting&quot; buttons {&quot;OK&quot;} with icon Stop' -e 'end tell'
    exit
  fi
&nbsp;
  # Generate random name
  while true; do
      name=`perl -e 'use MIME::Base64; $s=encode_base64(rand()); $s =~ s/=|\n//g; $s = substr($s, -5); print $s'`
      if ! grep &quot;$name&quot; &quot;$APPSUPPORT/Taken Names&quot; &amp;&gt;/dev/null; then break; fi;
  done;
&nbsp;
  # Gather info
  default=`php -r '$s = basename(&quot;'&quot;$f&quot;'&quot;); echo ucwords(strtolower(substr($s, 0, strpos($s, &quot;.&quot;))));'`
  title=`osascript -e 'tell application &quot;Finder&quot;' -e 'activate' -e 'text returned of (display dialog &quot;Enter image title&quot; with title &quot;Image Hosting&quot; default answer &quot;'&quot;$default&quot;'&quot; buttons {&quot;Cancel&quot;, &quot;Continue&quot;} default button 2)' -e 'end tell'`
  [ ! &quot;$title&quot; ] &amp;&amp; exit
  defaulttwitter=`cat &quot;$APPSUPPORT/Default Twitter Account&quot; 2&gt;/dev/null`
  twitter=`osascript -e 'tell application &quot;Finder&quot;' -e 'activate' -e 'text returned of (display dialog &quot;Enter Twitter account&quot; with title &quot;Image Hosting&quot; default answer &quot;'&quot;$defaulttwitter&quot;'&quot; buttons {&quot;Cancel&quot;, &quot;Continue&quot;} default button 2)' -e 'end tell'`
  [ ! &quot;$twitter&quot; ] &amp;&amp; exit
  echo $twitter &gt; &quot;$APPSUPPORT/Default Twitter Account&quot;
&nbsp;
  # Create temp files
  [ -e &quot;$TMPDIR&quot; ] &amp;&amp; rm -rf &quot;$TMPDIR&quot;
  mkdir &quot;$TMPDIR&quot;
  cp &quot;$f&quot; &quot;$TMPDIR/$name.jpg&quot;
  echo &quot;$title
$twitter&quot; &gt; &quot;$TMPDIR/$name.meta&quot;
&nbsp;
  [ -f &quot;$GROWL&quot; ] &amp;&amp; $GROWL -n 'Image Hosting' &quot;Image Hosting: `basename &quot;$f&quot;`&quot; -m &quot;Image Hosting is uploading '$name'&quot;
&nbsp;
  # Upload
  retries=0
  while [ $retries -lt $UPLOADRETRIES ]; do
    result=`scp &quot;$TMPDIR&quot;/* &quot;$DEST&quot; 2&gt;&amp;1` &amp;&amp; break;
    [ -f &quot;$GROWL&quot; ] &amp;&amp; $GROWL -n &quot;Image Hosting: `basename &quot;$f&quot;`&quot; 'Image Hosting' -m 'Upload failed: Retrying'
    retries=$((retries+1))
  done
&nbsp;
  if [ $retries -ge $UPLOADRETRIES ]; then
    osascript -e 'tell application &quot;Finder&quot;' -e 'activate' -e 'display dialog &quot;Could not upload image.  Scp said: '&quot;$result&quot;'&quot; with title &quot;Image Hosting&quot; with icon Stop' -e 'end tell'
    exit
  fi
&nbsp;
  echo $name &gt;&gt; &quot;$APPSUPPORT/Taken Names&quot;
&nbsp;
  osascript -e 'tell application &quot;Finder&quot; to set the clipboard to &quot;'&quot;$URLPREFIX$name&quot;'&quot;'
&nbsp;
  [ -f &quot;$GROWL&quot; ] &amp;&amp; $GROWL -n 'Image Hosting' &quot;Image Hosting: `basename &quot;$f&quot;`&quot; -m &quot;Upload complete.  Available at $URLPREFIX/$name (copied to clipboard)&quot;
done</pre></div></div>


<p>To use it:</p>

<ol>
<li>Unzip it, </li>
<li>Put it into <code>Library/Services</code>, </li>
<li>Double-click on it to open it in Automator,</li>
<li>Change the settings at the top of the &#8216;Shell Script&#8217; segment &#8212; 

<ul>
<li>Set <code>DEST</code> to the <code>scp</code> destination</li>
<li>Set up <a href="http://www.google.com/search?q=ssh%20authorized_keys">key-based SSH authentication</a>, so you don&#8217;t have to enter the password to upload, or, if you&#8217;d prefer to use something other than <code>scp</code> to upload the file, you can change the upload command further down in the script, underneath the &#8216;Upload&#8217; comment (look for <code>scp</code>)</li>
<li>Set <code>URLPREFIX</code> to <code>http://yoursite.com</code></li>
<li>If you have Growl and <code>growlnotify</code> installed, then set <code>GROWL</code> to the location of <code>growlnotify</code> (highly recommended)</li>
</ul></li>
<li>Save</li>
</ol>

<h2>Usage</h2>

<p>If you&#8217;re using Leopard, you may need to log out, then log back in to see the service &#8212; I&#8217;m not entirely certain.  If you&#8217;re on Snow Leopard, you should hopefully be set.  Right-click on an image file in Finder, and click &#8216;<em>Send Image to Image Hosting</em>&#8216;.</p>

<p>You should be asked for a title, then asked for a Twitter account name (this will be remembered for next time), then the upload will happen, and when it completes, the URL to the uploaded image will be put onto the clipboard so you can paste straight into Twitter.</p>

<p>Voila.</p>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1757" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/diy-twitter-image-hosting/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Unit testing and coverage with XCode</title>
		<link>http://atastypixel.com/blog/unit-testing-and-coverage-with-xcode/</link>
		<comments>http://atastypixel.com/blog/unit-testing-and-coverage-with-xcode/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 17:52:54 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Workflow]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/2009/11/29/unit-testing-and-coverage-with-xcode/</guid>
		<description><![CDATA[There are several great resources out there on how to incorporate unit testing into XCode projects. It&#8217;s all built into XCode now, and it&#8217;s fantastic. I just got coverage working too, thanks to a useful article at SuperMegaUltraGroovy on how to use code coverage with XCode. There were a couple of caveats that I thought [...]]]></description>
			<content:encoded><![CDATA[<p>There are several great resources out there on how to <a href="http://developer.apple.com/tools/unittest.html">incorporate</a> unit testing into XCode projects.  It&#8217;s all built into XCode now, and it&#8217;s fantastic.</p>

<p>I just got coverage working too, thanks to a useful article at SuperMegaUltraGroovy on how to use <a href="http://www.supermegaultragroovy.com/blog/2005/11/03/unit-testing-and-code-coverage-with-xcode/">code coverage with XCode</a>.  There were a couple of caveats that I thought I&#8217;d share, though.<span id="more-1685"></span>So, to repeat SMUG&#8217;s instructions:</p>

<ol>
<li>Set up <a href="http://developer.apple.com/tools/unittest.html">unit testing</a></li>
<li>Create a new build configuration (&#8216;Coverage&#8217;), duplicated from the &#8216;Debug&#8217; configuration</li>
<li>Open up build settings for the main target, make sure your new configuration is selected, and:

<ul>
<li>Enable &#8220;Generate Test Coverage Files&#8221;</li>
<li>Enable &#8220;Instrument Program Flow&#8221;</li>
<li>Add &#8220;<code>-lgcov</code>&#8221; to &#8220;Other Linker Flags&#8221;</li>
</ul></li>
</ol>

<p>SMUG proposes some commands to append to the &#8220;Run Script&#8221; build phase of the unit test target, in order to generate the coverage report and output a summary to the build results (see the original article).  I made some modifications to aid readability.  So, instead, I added the following to the &#8220;Run Script&#8221; phase of the unit test target:</p>


<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;"># Run gcov on the framework getting tested
if [ &quot;${CONFIGURATION}&quot; = 'Coverage' ]; then
     TARGET_NAME=&quot;My Application&quot;
     OBJ_DIR=${OBJROOT}/${TARGET_NAME}.build/${CONFIGURATION}/${TARGET_NAME}.build/Objects-normal/${CURRENT_ARCH}
     mkdir -p Coverage
     pushd Coverage
     find &quot;${OBJROOT}&quot; -name *.gcda -exec gcov -o &quot;${OBJ_DIR}&quot; {} \; 2&gt;/tmp/gconv-stderr | egrep &quot;^File|^Lines&quot; | sed -E &quot;s@File '$SRCROOT/@@;s@(\.[a-zA-Z])'@\1: @;s@Lines executed:([0-9.%]+) of ([0-9]+)@\1 (\2)@&quot; | paste -d&quot; &quot; - - | egrep -v &quot;^File '&quot; | sed -E &quot;s@^([^:]+):([^(]*)(\([^)]+\))@\2:\1\3@&quot; | sort -n | sed -E &quot;s@^([^:]+):([^(]*)(\([^)]+\))@\2:\1\3@&quot;; cat /tmp/gconv-stderr | grep -v &quot;version.*, prefer.*&quot;; rm /tmp/gconv-stderr
     popd
fi</pre></div></div>


<p>This orders the results by coverage percentage, reformats the output to be a bit terser and more readable, and suppresses some unnecessary warnings about GCC 4.0 (see below).</p>

<p>Finally, using XCode 3.2 on Snow Leopard (Mac OS X 10.6), I found that there were a few issues.  Using any SDK other than 10.6 results in build errors:</p>

<p><pre>
“<em>vproc_transaction_begin”, referenced from:
_</em>_gcov_init in libgcov.a(_gcov.o)
_vproc_transaction_begin$non_lazy_ptr in libgcov.a(_gcov.o)
“_vproc_transaction_end”, referenced from:
_gcov_exit in libgcov.a(_gcov.o)
_vproc_transaction_end$non_lazy_ptr in libgcov.a(_gcov.o)
ld: symbol(s) not found
</pre></p>

<p>The solution I found in the <a href="http://lists.apple.com/archives/xcode-users/2009/Sep/msg00066.html">Apple lists archives</a> is to use the same SDK as the OS: 10.6 (<em>Project menu, Set Active SDK, 10.6</em>).</p>

<p>After fixing this, I was getting dubious-looking results &#8211; mostly 0.00% code coverage except for a few random files.  The <a href="http://stackoverflow.com/questions/1385568/why-doesnt-gcov-report-any-lines-being-covered-by-my-unit-tests">suggestion</a> for this was to use GCC 4.0 instead of the default 4.2 (edit build settings for the main target, and probably the unit test target too, and select &#8220;GCC 4.0&#8243; under &#8220;C/C++ Compiler Version&#8221;).</p>

<p>After a clean and rebuild, I&#8217;m getting proper results.</p>

<p>Phew.</p>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1685" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/unit-testing-and-coverage-with-xcode/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Align comments in Textmate</title>
		<link>http://atastypixel.com/blog/align-comments-in-textmate/</link>
		<comments>http://atastypixel.com/blog/align-comments-in-textmate/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 12:30:02 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/2009/03/27/align-comments-in-textmate/</guid>
		<description><![CDATA[A Textmate command script to align comments in a block]]></description>
			<content:encoded><![CDATA[<p>Unless I&#8217;m using Objective-C, which is fantastically self-documenting, I often like to add comments to parameters to remind me of what they do.  For example:</p>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">imagecopy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #000088;">$frame</span><span style="color: #339933;">,</span> 
          <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #339933;">=</span><span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">-</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">topRightCap</span><span style="color: #009900;">&#91;</span>kCapWidth<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">topLeftCap</span><span style="color: #009900;">&#91;</span>kCapWidth<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Destination x</span>
          <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>  <span style="color: #666666; font-style: italic;">// Destination y</span>
          <span style="color: #000088;">$x</span><span style="color: #339933;">,</span>  <span style="color: #666666; font-style: italic;">// Source x</span>
          <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>  <span style="color: #666666; font-style: italic;">// Source y</span>
          <span style="color: #990000;">min</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">topRightCap</span><span style="color: #009900;">&#91;</span>kCapWidth<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">-</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">topLeftCap</span><span style="color: #009900;">&#91;</span>kCapWidth<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>  <span style="color: #666666; font-style: italic;">// Source width</span>
          <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">topRightCap</span><span style="color: #009900;">&#91;</span>kCapHeight<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Source height</span></pre></div></div>


<p>The only thing is, it looks terrible and is very hard to read.  I usually carefully insert spaces before the comments so they line up, but that&#8217;s really hard to maintain.</p>

<p>I use <a href="http://macromates.com/">Textmate</a>, and found an &#8216;Align Assignments&#8217; script by Chris Poirier which applies very nice formatting to a block of assignments.</p>

<p>Some trivial modifications resulted in a similar script to align comments. Hit <em>Ctrl-Option-Command-/</em>, and:</p>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">imagecopy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #000088;">$frame</span><span style="color: #339933;">,</span> 
          <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #339933;">=</span><span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">-</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">topRightCap</span><span style="color: #009900;">&#91;</span>kCapWidth<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">topLeftCap</span><span style="color: #009900;">&#91;</span>kCapWidth<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Destination x</span>
          <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>                                                                            <span style="color: #666666; font-style: italic;">// Destination y</span>
          <span style="color: #000088;">$x</span><span style="color: #339933;">,</span>                                                                           <span style="color: #666666; font-style: italic;">// Source x</span>
          <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>                                                                            <span style="color: #666666; font-style: italic;">// Source y</span>
          <span style="color: #990000;">min</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">topRightCap</span><span style="color: #009900;">&#91;</span>kCapWidth<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">-</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">topLeftCap</span><span style="color: #009900;">&#91;</span>kCapWidth<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>      <span style="color: #666666; font-style: italic;">// Source width</span>
          <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">topRightCap</span><span style="color: #009900;">&#91;</span>kCapHeight<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                                              <span style="color: #666666; font-style: italic;">// Source height</span></pre></div></div>


<p>Here it is:</p>

<p><a href="http://atastypixel.com/blog/wp-content/uploads/2009/03/align-commentstmcommand1.zip" title="Align Comments.tmCommand.zip">Align Comments.tmCommand.zip</a></p>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1559" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/align-comments-in-textmate/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Finder toolbar scripts for better workflow</title>
		<link>http://atastypixel.com/blog/finder-toolbar-scripts-for-better-workflow/</link>
		<comments>http://atastypixel.com/blog/finder-toolbar-scripts-for-better-workflow/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 11:10:39 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/2009/03/11/finder-toolbar-scripts-for-better-workflow/</guid>
		<description><![CDATA[I recently found two Finder toolbar scripts which are really going to make my life easier. The first one, Open In TextMate, will open either the current folder, or the selected item(s), in TextMate. The second, Open Terminal Here (and icon modification), will open a Terminal window at the current path.]]></description>
			<content:encoded><![CDATA[<p><img src="http://atastypixel.com/blog/wp-content/uploads/2009/03/200903111109.jpg" width="240" height="90" alt="200903111109.jpg" title="200903111109.jpg" class="alignright" />I recently found two Finder toolbar scripts which are really going to make my life easier.</p>

<p>The first one, <a href="http://henrik.nyh.se/2007/10/open-in-textmate-from-leopard-finder">Open In TextMate</a>, will open either the current folder, or the selected item(s), in TextMate.</p>

<p>The second, <a href="http://www.entropy.ch/software/applescript/">Open Terminal Here</a> (and <a href="http://henrik.nyh.se/2007/10/open-terminal-here-and-glob-select-in-leopard-finder">icon modification</a>), will open a Terminal window at the current path.</p>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1490" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/finder-toolbar-scripts-for-better-workflow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Website maintenance with Textmate and FTP/SSH Bundle</title>
		<link>http://atastypixel.com/blog/website-maintenance-with-textmate-and-ftpssh-bundle/</link>
		<comments>http://atastypixel.com/blog/website-maintenance-with-textmate-and-ftpssh-bundle/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 00:54:21 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://atastypixel.com/blog/2009/01/28/website-maintenance-with-textmate-and-ftpssh-bundle/</guid>
		<description><![CDATA[I tend to work on local copies of my websites, which have either corresponding vhost entries in my local Apache configuration, or are simply symlinked to my ~/Sites folder. That way, I can test to make sure everything&#8217;s 100% before I make changes live. This has typically been a bit of a messy workflow &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>I tend to work on local copies of my websites, which have either corresponding <em>vhost</em> entries in my local Apache configuration, or are simply symlinked to my <em>~/Sites</em> folder.  That way, I can test to make sure everything&#8217;s 100% before I make changes live.</p>

<p>This has typically been a bit of a messy workflow &#8211; I make changes, and then when happy, either open up a terminal and <em>rsync</em> the whole lot over, or open up Flow/Transmit and manually copy the changed files over.  The whole thing makes me disinclined to make changes at all!</p>

<p>That is, until on a whim, I did a google search for a Textmate FTP bundle, and found Bernhard Fürst&#8217;s <a href="http://fuerstnet.de/en/ftpssh-bundle-textmate">FTP/SSH Bundle for Textmate</a>. This little gem lets you configure FTP settings for a project, then hit Option-S to save to the remote server, or Option-R to reload from the remote server.  This way, when I&#8217;m happy with the changes, I just whack Option-S to send them to the server straight from Textmate.</p>

<p>That makes me happy.</p>

<p>One little caveat &#8211; the bundle does an odd thing with the project directory, opting to use the parent folder of the Textmate project file, something which won&#8217;t work for ad hoc projects, when one just drags a folder into Textmate (one of my favourite features).  A quick fix:</p>

<ol>
<li>Find <em>Library/Application Support/TextMate/Bundles/FTP-SSH</em> and open its contents</li>
<li>Open up <em>Support/lib/helper_functions.php</em></li>
<li>Change the <code>$PROJECT_DIR</code> definition on line 15 to:

<p><code>$PROJECT_DIR = $_ENV['TM_PROJECT_DIRECTORY'];</code></p></li>
</ol>

<p>Voila!</p>
 <img src="http://atastypixel.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1323" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://atastypixel.com/blog/website-maintenance-with-textmate-and-ftpssh-bundle/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
