<?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>Radamanthus Batnag &#187; ruby</title>
	<atom:link href="http://rad.batnag.org/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://rad.batnag.org</link>
	<description>Random thoughts on web and indie game development.</description>
	<lastBuildDate>Sun, 31 Jul 2011 09:22:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Ruby Hacking Secrets From Barney Stinson</title>
		<link>http://rad.batnag.org/2011/04/ruby-hacking-secrets-from-barney-stinson/</link>
		<comments>http://rad.batnag.org/2011/04/ruby-hacking-secrets-from-barney-stinson/#comments</comments>
		<pubDate>Wed, 13 Apr 2011 15:39:27 +0000</pubDate>
		<dc:creator>rad</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://rad.batnag.org/?p=162</guid>
		<description><![CDATA[Introduction Yup, that guy from How I Met Your Mother. Ever wonder how he manages to hook up with pretty girls so easily? Is it the suit? The money? The good looks? Actually, his secret is his Ruby ninja skillz. I&#8217;m sure you&#8217;re familiar with the adage &#8220;Success is being in the right place at [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>Yup, that guy from How I Met Your Mother. Ever wonder how he manages to hook up with pretty girls so easily? Is it the suit? The money? The good looks? Actually, his secret is his Ruby ninja skillz.</p>
<p>I&#8217;m sure you&#8217;re familiar with the adage &#8220;Success is being in the right place at the right time&#8221;. For the purposes of this discussion, success means getting to hook up with a pretty girl. The right place is right beside the target girl, whoever she is. The right time is when she&#8217;s lonely, desperate, or horny. </p>
<p>How does Barney find the right place and the right time? You guessed it right, by stalking them on Facebook.</p>
<p>But Barney doesn&#8217;t use the lame Facebook search form. That&#8217;s too inefficient for him. He uses Ruby, the Facebook API, and the awesome <a href="https://github.com/nov/fb_graph" onclick="pageTracker._trackPageview('/outgoing/github.com/nov/fb_graph?referer=');">fb_graph</a> gem. In this article, I&#8217;ll give you a peek at the awesome Facebook stalking and searching you can do using these three tools.</p>
<p>SETUP</p>
<p>I&#8217;m assuming you already have Ruby 1.9.2 installed. MRI, <a href="http://www.macruby.org/" onclick="pageTracker._trackPageview('/outgoing/www.macruby.org/?referer=');">MacRuby</a>, whatever, as long as it implements 1.9.2 and you run it using <a href="https://rvm.beginrescueend.com/" onclick="pageTracker._trackPageview('/outgoing/rvm.beginrescueend.com/?referer=');">RVM</a>.</p>
<p>After that, all you really need is the fb_graph gem:</p>
<div class="code">
<code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> fb_graph</pre></td></tr></table></div>

<p></code>
</div>
<p><strong>Searching Facebook Using fb_graph</strong></p>
<div class="code">
<code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">irb
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'fb_graph'</span></pre></td></tr></table></div>

<p></code>
</div>
<p>Let&#8217;s search for the word &#8216;lonely&#8217;.</p>
<div class="code">
<code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">results = <span style="color:#6666ff; font-weight:bold;">FbGraph::Searchable</span>.<span style="color:#9900CC;">search</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'lonely'</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p></code>
</div>
<p>Yep, it&#8217;s that easy! What you get is an Array of Hashes, each hash containing a search result. </p>
<p>After taking a closer look at the results, you probably don&#8217;t like most of what you got &#8211; most are people who &#8220;Liked&#8221; Justin Bieber&#8217;s recent song, &#8220;One Less Lonely Girl&#8221;.</p>
<p>So let&#8217;s refine our search a little. Let&#8217;s get only search for Facebook statuses. Yep, that&#8217;s most likely what we want &#8211; girls who have out &#8220;I&#8217;m lonely&#8221; in their status.</p>
<div class="code">
<code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">results = FbGraph::Searchable.search<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'lonely'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>.
              <span style="color: #000000; font-weight: bold;">select</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000; font-weight: bold;">|</span>r<span style="color: #000000; font-weight: bold;">|</span> r<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">'type'</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #ff0000;">'status'</span> == r<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">'type'</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p></code>
</div>
<p>Now all the results are just <a href="http://developers.facebook.com/docs/reference/api/status/" onclick="pageTracker._trackPageview('/outgoing/developers.facebook.com/docs/reference/api/status/?referer=');">status messages</a>.</p>
<p>We can refine this further, though. We want to get only those that point to a <a href="http://developers.facebook.com/docs/reference/api/user/" onclick="pageTracker._trackPageview('/outgoing/developers.facebook.com/docs/reference/api/user/?referer=');">User</a> object, because that&#8217;s what we&#8217;re really after (evil grin).</p>
<div class="code">
<code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">  results = FbGraph::Searchable.search<span style="color: #7a0874; font-weight: bold;">&#40;</span>search_string<span style="color: #7a0874; font-weight: bold;">&#41;</span>.
    <span style="color: #000000; font-weight: bold;">select</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000; font-weight: bold;">|</span>r<span style="color: #000000; font-weight: bold;">|</span> r<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">'type'</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #ff0000;">'status'</span> == r<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">'type'</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>.
    <span style="color: #000000; font-weight: bold;">select</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000; font-weight: bold;">|</span>r<span style="color: #000000; font-weight: bold;">|</span> r<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">'from'</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> r<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">'from'</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">'id'</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p></code>
</div>
<p>You might want to take a peek at the users you got from your search:</p>
<div class="code">
<code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">r = results.first
=<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>too long, snipped<span style="color: #000000; font-weight: bold;">&gt;</span>
user = FbGraph::User.fetch<span style="color: #7a0874; font-weight: bold;">&#40;</span>r<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">'from'</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">'id'</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
=<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>too long, snipped<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
user.name
=<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">&quot;Lolita Bonita&quot;</span>
&nbsp;
user.picture
=<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">&quot;https://graph.facebook.com/800200356633259/picture&quot;</span></pre></td></tr></table></div>

<p></code>
</div>
<p>And the actual status:</p>
<div class="code">
<code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">r<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">'message'</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
=<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">&quot;I'm so lonely. I really need a guy beside me.&quot;</span></pre></td></tr></table></div>

<p></code>
</div>
<p>Now we&#8217;re on to something!</p>
<p>A little bit more scripting, and we can automate the download of those user pics!</p>
<p><strong>For The tl;dr Crowd</strong></p>
<p>If you&#8217;re too lazy to do all that Ruby, you can download <a href="https://github.com/radamanthus/barney_facebook_search" onclick="pageTracker._trackPageview('/outgoing/github.com/radamanthus/barney_facebook_search?referer=');">my project on github</a> and just run it:</p>
<div class="code">
<code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">ruby run.rb lonely results.html</pre></td></tr></table></div>

<p></code>
</div>
<p>This will run a Facebook search for &#8216;lonely&#8217;, download the profile pics of the matching users, and put their name, picture and status (with link to their facebook page) in an HTML file, results.html.</p>
<p>This is&#8230;Legendary!</p>
<p><em>This article was also posted <a href="http://info.exist.com/blogs/bid/47233/Ruby-Hacking-Secrets-from-Barney-Stinson" onclick="pageTracker._trackPageview('/outgoing/info.exist.com/blogs/bid/47233/Ruby-Hacking-Secrets-from-Barney-Stinson?referer=');">here</a></em>. You can also view more articles there from my awesome colleagues at <a href="http://www.exist.com/" onclick="pageTracker._trackPageview('/outgoing/www.exist.com/?referer=');">Exist</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://rad.batnag.org/2011/04/ruby-hacking-secrets-from-barney-stinson/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>XMPP Development in Ruby</title>
		<link>http://rad.batnag.org/2010/10/xmpp-development-in-ruby/</link>
		<comments>http://rad.batnag.org/2010/10/xmpp-development-in-ruby/#comments</comments>
		<pubDate>Sun, 17 Oct 2010 13:53:40 +0000</pubDate>
		<dc:creator>rad</dc:creator>
				<category><![CDATA[web]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[xmpp]]></category>

		<guid isPermaLink="false">http://rad.batnag.org/?p=152</guid>
		<description><![CDATA[Recently I wasted a day and half in debugging an XMPP-based service I&#8217;m working on. As is usual, the real reason I lost so much time was because I was totally unfamiliar with the terrain. I should have spent an hour or two on XMPP basics before I waded into this unfamiliar territory. If you&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I wasted a day and half in debugging an XMPP-based service I&#8217;m working on. As is usual, the real reason I lost so much time was because I was totally unfamiliar with the terrain. I should have spent an hour or two on XMPP basics before I waded into this unfamiliar territory.</p>
<p>If you&#8217;re just starting on XMPP development with Ruby, here are some tips and resources that you might find useful.</p>
<p><strong>One client at a time</strong><br />
For each account, there should only be one XMPP client logged in at any time. If client A is already logged in, and then client B logs in, client A will be disconnected and will stop receiving notifications. Just like in Yahoo! Messenger: when you login from a second client, the first client will be disconnected. It&#8217;s so basic, but I managed to waste the better part of a day on debugging perfectly working code before I realized that this was what&#8217;s going on in my system.</p>
<p><strong>Use <a href="http://github.com/mojodna/switchboard/tree" onclick="pageTracker._trackPageview('/outgoing/github.com/mojodna/switchboard/tree?referer=');">switchboard</a> for testing</strong><br />
When debugging network applications, you want to make sure that the application is indeed the problem and not the network. For web applications, you use <a href="http://en.wikipedia.org/wiki/CURL" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/CURL?referer=');">curl</a> for testing. switchboard aims to be the curl for XMPP development.  curl is a command-line (hence scriptable!) http client; XMPP is a command-line XMPP client.</p>
<p>github page: <a href="http://github.com/mojodna/switchboard/tree" onclick="pageTracker._trackPageview('/outgoing/github.com/mojodna/switchboard/tree?referer=');">http://github.com/mojodna/switchboard/tree</a><br />
command-line usage: <a href="http://mojodna.net/2009/07/16/switchboard-curl-for-xmpp.html" onclick="pageTracker._trackPageview('/outgoing/mojodna.net/2009/07/16/switchboard-curl-for-xmpp.html?referer=');">http://mojodna.net/2009/07/16/switchboard-curl-for-xmpp.html</a></p>
<p><strong>Useful Resources</strong><br />
If you&#8217;re going to do XMPP development in plain Ruby, there&#8217;s a <a href="http://peepcode.com/products/xmpp" onclick="pageTracker._trackPageview('/outgoing/peepcode.com/products/xmpp?referer=');">peepcode screencast</a> that you might find useful. It might be a bit dated, though, and most likely there are higher-level libraries that you can use.</p>
<p>In my case, I was working on harvesting blog entries from Superfeedr, so I use the Superfeedr gem, <a href="http://github.com/superfeedr/superfeedr-ruby" onclick="pageTracker._trackPageview('/outgoing/github.com/superfeedr/superfeedr-ruby?referer=');">superfeedr-ruby</a>. An alternative is the more streamlined and highly opinionated <a href="http://github.com/superfeedr/superfeedr-rb" onclick="pageTracker._trackPageview('/outgoing/github.com/superfeedr/superfeedr-rb?referer=');">superfeedr-rb</a>.</p>
<p>Even if you&#8217;re not doing Superfeedr work, it&#8217;s worth spending the time to study superfeedr-ruby, if only to study how it uses Skates. <a href="http://github.com/julien51/skates" onclick="pageTracker._trackPageview('/outgoing/github.com/julien51/skates?referer=');">Skates</a> (formerly Babylon) is a framework for building XMPP applications in Ruby, using EventMachine for handling connections.</p>
]]></content:encoded>
			<wfw:commentRss>http://rad.batnag.org/2010/10/xmpp-development-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>work.sh</title>
		<link>http://rad.batnag.org/2010/06/work-sh/</link>
		<comments>http://rad.batnag.org/2010/06/work-sh/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 17:24:34 +0000</pubDate>
		<dc:creator>rad</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://rad.batnag.org/?p=86</guid>
		<description><![CDATA[Ideally, there's a one-click work button, a sideproject1 button, a sideproject2 button, etc. Press the right button and your Mac will be transformed into a mode optimized for the work to be done: run the needed apps, close unneeded apps, start your favorite music, change the desktop background, etc.

I have decided to learn AppleScript to build those magic buttons. Here's what I've come up with so far.]]></description>
			<content:encoded><![CDATA[<p>From a cold boot, to start working on one of my Rails projects, I need to do the following:</p>
<ul>
<ol/> open Terminal, then Start MySQL or PostgreSQL</p>
<ol/> in a separate Terminal tab: cd Documents/projects/
<projectname> ; mate .</p>
<ol/> (if applicable) in a separate Terminal tab: Start Solr or Ferret</p>
<ol/> Start Firefox</p>
<ol/> Start Evernote
</ul>
<p>That&#8217;s a lot of keystrokes and mouse actions. No wonder I end up playing games most of the time, because Age of Empires III takes just one click.</p>
<p>I can configure MySQL and PostgreSQL to run on startup, but that&#8217;s wasteful. That&#8217;ll slow down the machine&#8217;s startup time, and sometimes I use just MySQL, on other projects I use PostgreSQL, and on other projects I use neither but instead use MongoDB. And that will just take away one step in this 5-step process to get from cold bootup to work bliss.</p>
<p>Ideally, there&#8217;s a one-click work button, a sideproject1 button, a sideproject2 button, etc. Press the right button and the Mac will be transformed into a mode optimized for the work to be done: run the needed apps, close unneeded apps, play music from the &#8220;work playlist&#8221;, change the desktop background, etc.</p>
<p>I have decided to learn AppleScript to build those magic buttons. Here&#8217;s what I&#8217;ve come up with so far:</p>
<div class="code">
<code></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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
</pre></td><td class="code"><pre class="applescript" style="font-family:monospace;">#!<span style="color: #000000;">/</span>bin<span style="color: #000000;">/</span>sh
&nbsp;
# <span style="color: #ff0033; font-weight: bold;">From</span>: http:<span style="color: #000000;">//</span>stackoverflow.com<span style="color: #000000;">/</span>questions<span style="color: #000000;">/</span><span style="color: #000000;">1589114</span><span style="color: #000000;">/</span>opening<span style="color: #000000;">-</span>a<span style="color: #000000;">-</span>new<span style="color: #000000;">-</span>terminal<span style="color: #000000;">-</span>tab<span style="color: #000000;">-</span>in<span style="color: #000000;">-</span>osxsnow<span style="color: #000000;">-</span>leopard<span style="color: #000000;">-</span>with<span style="color: #000000;">-</span>the<span style="color: #000000;">-</span>opening<span style="color: #000000;">-</span>terminal<span style="color: #000000;">-</span>windows<span style="color: #000000;">/</span><span style="color: #000000;">1590818</span>#<span style="color: #000000;">1590818</span>
# <span style="color: #000000;">&#40;</span>See answer <span style="color: #0066ff;">by</span> i0n that says <span style="color: #009900;">&quot;courtesy of Dan Benjamin&quot;</span> http:<span style="color: #000000;">//</span>twitter.com<span style="color: #000000;">/</span>danbenjamin<span style="color: #000000;">&#41;</span>
&nbsp;
# Sets up <span style="color: #ff0033; font-weight: bold;">my</span> Infinitely terminal windows
&nbsp;
# <span style="color: #000000;">1</span>. <span style="color: #0066ff;">Run</span> MongoDB
# <span style="color: #000000;">2</span>. <span style="color: #0066ff;">Run</span> redis <span style="color: #ff0033; font-weight: bold;">in</span> a <span style="color: #0066ff;">new</span> terminal <span style="color: #0066ff;">tab</span>
# <span style="color: #000000;">3</span>. cd <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">the</span> project
# <span style="color: #000000;">4</span>. <span style="color: #0066ff;">Launch</span> Evernote
# <span style="color: #000000;">5</span>. <span style="color: #0066ff;">Launch</span> Firefox
# <span style="color: #000000;">6</span>. <span style="color: #0066ff;">Launch</span> GitX
&nbsp;
&nbsp;
# <span style="color: #000000;">1</span>. <span style="color: #0066ff;">Run</span> MongoDB <span style="color: #ff0033; font-weight: bold;">in</span> a <span style="color: #0066ff;">new</span> terminal
<span style="color: #000000;">/</span>usr<span style="color: #000000;">/</span>bin<span style="color: #000000;">/</span>osascript <span style="color: #000000;">&lt;&lt;</span>mongo
<span style="color: #0066ff;">activate</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Terminal&quot;</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>
	keystroke <span style="color: #009900;">&quot;t&quot;</span> using <span style="color: #000000;">&#123;</span>command down<span style="color: #000000;">&#125;</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;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Terminal&quot;</span>
	<span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> win <span style="color: #ff0033; font-weight: bold;">in</span> windows
		<span style="color: #ff0033; font-weight: bold;">try</span>
			<span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #ff0033; font-weight: bold;">get</span> frontmost <span style="color: #ff0033; font-weight: bold;">of</span> win <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #0066ff;">true</span> <span style="color: #ff0033; font-weight: bold;">then</span>
				do <span style="color: #ff0033; font-weight: bold;">script</span> <span style="color: #009900;">&quot;cd ~; ./mongo.sh&quot;</span> <span style="color: #ff0033; font-weight: bold;">in</span> <span style="color: #000000;">&#40;</span>selected <span style="color: #0066ff;">tab</span> <span style="color: #ff0033; font-weight: bold;">of</span> win<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;">try</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;">tell</span>
mongo
&nbsp;
# <span style="color: #000000;">2</span>. <span style="color: #0066ff;">Run</span> redis <span style="color: #ff0033; font-weight: bold;">in</span> a <span style="color: #0066ff;">new</span> terminal
<span style="color: #000000;">/</span>usr<span style="color: #000000;">/</span>bin<span style="color: #000000;">/</span>osascript <span style="color: #000000;">&lt;&lt;</span>redis
<span style="color: #0066ff;">activate</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Terminal&quot;</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>
	keystroke <span style="color: #009900;">&quot;t&quot;</span> using <span style="color: #000000;">&#123;</span>command down<span style="color: #000000;">&#125;</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;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Terminal&quot;</span>
	<span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> win <span style="color: #ff0033; font-weight: bold;">in</span> windows
		<span style="color: #ff0033; font-weight: bold;">try</span>
			<span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #ff0033; font-weight: bold;">get</span> frontmost <span style="color: #ff0033; font-weight: bold;">of</span> win <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #0066ff;">true</span> <span style="color: #ff0033; font-weight: bold;">then</span>
				do <span style="color: #ff0033; font-weight: bold;">script</span> <span style="color: #009900;">&quot;cd ~; ./redis.sh&quot;</span> <span style="color: #ff0033; font-weight: bold;">in</span> <span style="color: #000000;">&#40;</span>selected <span style="color: #0066ff;">tab</span> <span style="color: #ff0033; font-weight: bold;">of</span> win<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;">try</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;">tell</span>
redis
&nbsp;
# <span style="color: #000000;">3</span>. cd <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">the</span> workers project
<span style="color: #000000;">/</span>usr<span style="color: #000000;">/</span>bin<span style="color: #000000;">/</span>osascript <span style="color: #000000;">&lt;&lt;</span>workers
<span style="color: #0066ff;">activate</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Terminal&quot;</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>
	keystroke <span style="color: #009900;">&quot;t&quot;</span> using <span style="color: #000000;">&#123;</span>command down<span style="color: #000000;">&#125;</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;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Terminal&quot;</span>
	<span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> win <span style="color: #ff0033; font-weight: bold;">in</span> windows
		<span style="color: #ff0033; font-weight: bold;">try</span>
			<span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #ff0033; font-weight: bold;">get</span> frontmost <span style="color: #ff0033; font-weight: bold;">of</span> win <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #0066ff;">true</span> <span style="color: #ff0033; font-weight: bold;">then</span>
				do <span style="color: #ff0033; font-weight: bold;">script</span> <span style="color: #009900;">&quot;cd ~/Documents/projects/infinitely/workers; mate .&quot;</span> <span style="color: #ff0033; font-weight: bold;">in</span> <span style="color: #000000;">&#40;</span>selected <span style="color: #0066ff;">tab</span> <span style="color: #ff0033; font-weight: bold;">of</span> win<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;">try</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;">tell</span>
workers
&nbsp;
<span style="color: #0066ff;">sleep</span> <span style="color: #000000;">1</span>
# <span style="color: #000000;">4</span>. <span style="color: #0066ff;">Launch</span> Evernote
<span style="color: #0066ff;">open</span> <span style="color: #000000;">/</span>Applications<span style="color: #000000;">/</span>Evernote.app
&nbsp;
# <span style="color: #000000;">5</span>. <span style="color: #0066ff;">Launch</span> Firefox
<span style="color: #0066ff;">open</span> <span style="color: #000000;">/</span>Applications<span style="color: #000000;">/</span>Firefox.app
&nbsp;
clear</pre></td></tr></table></div>

<p></code>
</div>
<p>There&#8217;s still no &#8220;Open iTunes and play songs in my &#8216;work&#8217; playlist&#8221; section, but I&#8217;m working on it. And here&#8217;s something to make it more interesting: <a href="http://www.apeth.com/rbappscript/00intro.html" onclick="pageTracker._trackPageview('/outgoing/www.apeth.com/rbappscript/00intro.html?referer=');">AppleScripting with Ruby</a>!</p>
<p><em>This script borrowed heavily from the ideas of the people in this <a href="http://stackoverflow.com/questions/1589114/opening-a-new-terminal-tab-in-osxsnow-leopard-with-the-opening-terminal-windows/1590818#1590818" onclick="pageTracker._trackPageview('/outgoing/stackoverflow.com/questions/1589114/opening-a-new-terminal-tab-in-osxsnow-leopard-with-the-opening-terminal-windows/1590818_1590818?referer=');">Stackoverflow thread</a>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://rad.batnag.org/2010/06/work-sh/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

