<?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>Hackerdude &#187; Ruby</title>
	<atom:link href="http://www.hackerdude.com/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hackerdude.com</link>
	<description>Software Development Blog by David Martinez</description>
	<lastBuildDate>Tue, 06 Apr 2010 05:02:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>JIRA To Omnifocus Script</title>
		<link>http://www.hackerdude.com/2009/03/04/jira-to-omnifocus-script/</link>
		<comments>http://www.hackerdude.com/2009/03/04/jira-to-omnifocus-script/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 18:47:37 +0000</pubDate>
		<dc:creator>David Martinez</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://www.hackerdude.com/2009/03/04/jira-to-omnifocus-script/</guid>
		<description><![CDATA[This script logs into your JIRA and creates OmniFocus tasks for each of the JIRA items that are assigned to you, so they sync to your Omnifocus for iPhone, you only have to keep track of one inbox, etc. It only takes a tiny bit of setup. Setting up To set this up, do the [...]]]></description>
			<content:encoded><![CDATA[<p>This script logs into your <a href="http://www.atlassian.com/software/jira/" title="JIRA: Task Tracking Software">JIRA</a> and creates <a href="http://www.omnigroup.com/applications/omnifocus/" title="Omnifocus - Professional Grade Desktop Task Mnagement">OmniFocus</a> tasks for each of the JIRA items that are assigned to you, so they sync to your Omnifocus for iPhone, you only have to keep track of one inbox, etc. It only takes a tiny bit of setup.</p>
<p><span id="more-548"></span>
<div class="setup_instructions">
<h4>Setting up</h4>
<p>To set this up, do the following:</p>
<ol>
<li><a href="http://www.hackerdude.com/wp-content/sample_code/jiratoomnifocus.zip">Download the script</a> and put it somewhere it will run</li>
<li>Install the required gems (<a href="http://appscript.sourceforge.net/" title="Appscript - Ruby applescript automation">appscript</a>, <a href="http://crypt.rubyforge.org/" title="Crypt: pure-ruby cryptographic cyphers">crypt</a>, <a href="http://gilesbowkett.blogspot.com/2008/09/password-gem-v12-released.html">password</a>) with gem install.</li>
<li>Go to JIRA and create a saved filter with whatever settings you like. Note the filter ID.</li>
<li>Go to the top of the jiratoomnifocus file and set it on the JIRA_FILTER_ID constant, and set the JIRA_BASE_URL to the URL of your JIRA installation.</li>
<li>If you like to keep your system very secure, take a look at the security warning, below, at this time</li>
<li>Run it. You will be asked to login the first time. After it's done, note the new tasks on your Omnifocus. Delete a task and run it again to see it add it again without asking you for authentication.</li>
</ol>
<p>You're set up! Now you can put it on a cron line, like this one which sets it to run at office hours (use cron -e on Terminal for this):</p>
<pre>
0,10,20,30,40,50 7-18 * * * /yourdir/jiratoomnifocus > /yourdir//log/jira_to_omnifocus.log 2>&#38;1
</pre>
<p>Congratulations! You now have only one inbox again. Let me know if you use it; I'd love to know of more ideas on how we can make it better/easier to setup.</p>
<div class="security_warning">
<h4>Security Warning</h4>
<p>The password for your JIRA account will be saved on a file on your computer called ~/.hackerdude/jira_credentials.yml. It is encrypted using blowfish using a constant key.</p>
<p>As long as both your jiratoomnifocus script and your credentials file are secured as (chmod 700 and owned by the user that will be running it on cron), you should be okay and secure (unless someone breaks into your account, in which case you have bigger problems than your JIRA access!). The crypt key used is a constant on the jiratoomnifocus script. Change the CRYPT_KEY key for any other random string of the same length and delete the jira_credentials.yml file (so it asks for your password again) and it will be recreated using your key the next time you start it.</p>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.hackerdude.com/2009/03/04/jira-to-omnifocus-script/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Ruby Appscript &#8211; Sweet automation</title>
		<link>http://www.hackerdude.com/2009/01/23/ruby-appscript-sweet-automation/</link>
		<comments>http://www.hackerdude.com/2009/01/23/ruby-appscript-sweet-automation/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 00:50:26 +0000</pubDate>
		<dc:creator>David Martinez</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.hackerdude.com/2009/01/23/ruby-appscript-sweet-automation/</guid>
		<description><![CDATA[Yesterday a coworker pointed me to ruby's appscript. I have found it nothing short of amazing. I love my Mac, and many of us like the idea of automating our software, until we try to use AppleScript to do it. To say that Applescript is professional developer unfriendly is an understatement. I like ruby but [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday a coworker pointed me to ruby's appscript. I have found it nothing short of amazing.</p>
<p>I love my Mac, and many of us like the idea of automating our software, until we try to use AppleScript to do it. To say that Applescript is professional developer unfriendly is an understatement. I like ruby but to make ruby and applescript talk requires sending strings to osascript in just the right way and getting the output from osascript back. Not a lot of fun at all.</p>
<p>Enter appscript. <a href="http://appscript.sourceforge.net/" title="Appscript - Ruby applescript automation">Appscript</a> is a ruby library that interfaces with applescript seamlessly.</p>
<p><span id="more-541"></span>
<p>What's pretty amazing is its power after you spend a little while on the irb console and keep using the tab key for autocompletion. It even introspects the dictionary to see what is available at this time. It doesn't always give the right thing but by trying things out and with a bit of logic you always get there. </p>
<p>There's also an app called ASDictionary that will spit out the dictionary with ruby syntax, though I never found the dictionary all that useful anyway (I mean yes, it has definitions for everything, but it seldom provides info on exactly how everything is tied together or examples of use). I personally prefer trying things out on the console.</p>
<p>Here are a few examples of its use. You can do all this on irb immediately after installing it with <strong>sudo gem install appscript</strong>:</p>
<h4>Driving iCal</h4>
<p>This will get all your calendars and print their names:</p>
<pre class="ruby">&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'appscript'</span>
app = Appscript.<span style="color:#9900CC;">app</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;iCal&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
app.<span style="color:#9900CC;">calendars</span>.<span style="color:#9900CC;">get</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> |cal| <span style="color:#CC0066; font-weight:bold;">puts</span> cal.<span style="color:#9900CC;">name</span>.<span style="color:#9900CC;">get</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;</pre>
<p>Just expanding on this concept a little more, you can also grab all the to-dos:  </p>
<pre class="ruby">&nbsp;
app.<span style="color:#9900CC;">calendars</span>.<span style="color:#9900CC;">get</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> |cal|
  cal.<span style="color:#9900CC;">get</span>.<span style="color:#9900CC;">todos</span>.<span style="color:#9900CC;">get</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span>|todo|
    <span style="color:#CC0066; font-weight:bold;">puts</span> todo.<span style="color:#9900CC;">summary</span>.<span style="color:#9900CC;">get</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;</pre>
<h4>Automating Safari. Ruby to Applescript to Javascript</h4>
<p>Haven't tried marshaling values back as I'm just exploring, but I don't see why it couldn't.</p>
<pre class="ruby">&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'appscript'</span>
app = Appscript.<span style="color:#9900CC;">app</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;iCal&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
app.<span style="color:#9900CC;">open_location</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;http://www.google.com&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
window = app.<span style="color:#9900CC;">documents</span>.<span style="color:#9900CC;">get</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>
window.<span style="color:#9900CC;">do_JavaScript</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;window.alert('Your title is '+document.title)&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;</pre>
<p>I'm sure you can find some use for this. I already did - I wrote myself a quick cron to add all the JIRA tasks assigned to me to <a href="http://www.omnigroup.com/applications/omnifocus/" title="Omnifocus - Professional Grade Desktop Task Mnagement">Omnifocus</a> if I don't already have them there. I'm looking forward to seeing what else I can put this to use.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hackerdude.com/2009/01/23/ruby-appscript-sweet-automation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ruby, Folder actions and full automation</title>
		<link>http://www.hackerdude.com/2008/09/25/ruby-folder-actions-and-full-automation/</link>
		<comments>http://www.hackerdude.com/2008/09/25/ruby-folder-actions-and-full-automation/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 00:03:37 +0000</pubDate>
		<dc:creator>David Martinez</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.hackerdude.com/2008/09/25/ruby-folder-actions-and-full-automation/</guid>
		<description><![CDATA[I routinely scan my documents as PDFs so I can keep them in a virtual filing cabinet (you know, the whole "paperless office" thing). I use my HP all-in-one software running on a Windows VM inside a Mac (sorry, but the Mac scanning software on HP is complete garbage in my opinion). What bothered me [...]]]></description>
			<content:encoded><![CDATA[<p>I routinely scan my documents as PDFs so I can keep them in a virtual filing cabinet (you know, the whole "paperless office" thing). I use my HP all-in-one software running on a Windows VM inside a Mac (sorry, but the Mac scanning software on HP is complete garbage in my opinion).</p>
<p>What bothered me about this was that all the files scanned always end up named "scan12345.pdf". Because of the way I file, I like having my things as "year/company/year-monty-date.pdf" instead.</p>
<p><span id="more-532"></span></p>
<p>For a while there I was spending hours manually moving files to the correct folders while watching TV or doing another "using half-my-brain" activity. I thought there had to be a better way. I'm a bit handy with software, so I started a little ruby script to do the move for me.</p>
<p>The script uses pdftotext (you can get pdftotext using <a href="http://www.macports.org">MacPorts</a>  ) and ruby to determine information inside the actual PDF (scan them as "searchable PDFs" so it OCRs the text). Once it makes that determination, it does the file move to the appropriate place. A series of Regular expressions inside the script determine what company it belongs to, and a strong date parser takes a look at anything that looks significant enough that has a date attached to it in order to determine an appropriate date IN the scanned document, as opposed to the date of the file (which it uses if it can't find any parsable dates inside the document).</p>
<p>So now I had a script that could do those moves properly, but still didn't want to have to remember to continuously running the script. Here is where the Mac's Folder Actions feature comes in.</p>
<p>Using Folder Actions, I wrote the following script to wait for the file to drop in the folder (the scanning program on the Windows side uses a VMWare shared folder to drop the PDF on a mac folder):</p>
<p>It's not perfect. It uses a delay mechanism to wait for the Windows side to finish writing the PDF (dumb scanning program creates the zero-byte file and waits to fill it until it has run OCR on the whole thing). But because the folder action works on all PDFs on the document, it can pick up the ones it couldn't run pdftotext on the last time, so it's good enough for now. It also has a real problem pulling the correct date on documents where a lot of patterns could be a date (need to work on a good algorithm - I haven't found one yet).</p>
<p>Anyway, here are <a href="http://www.hackerdude.com/wp-content/sample_code/auto_file.rb">the auto_file script</a> and the <a href="http://www.hackerdude.com/wp-content/sample_code/added_scanned_doc.applescript.txt">applescript folder actions script</a> that triggers it.</p>
<p>Hopefully it will be useful for you if you have a similar need or just for learning how you can streamline some of the stuff you do every day with your Mac. Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hackerdude.com/2008/09/25/ruby-folder-actions-and-full-automation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
