<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>hi, it&#39;s mike</title>
    <link>https://mike.puddingtime.org/tags/yojimbo/</link>
    <description>Recent content on hi, it&#39;s mike</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <managingEditor>mike@puddingtime.org (mike)</managingEditor>
    <webMaster>mike@puddingtime.org (mike)</webMaster>
    <copyright>© 2026, mike</copyright>
    <lastBuildDate>Sun, 18 Jan 2009 12:35:32 +0000</lastBuildDate>
    <atom:link href="https://mike.puddingtime.org/tags/yojimbo/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Quixotic, Appscript, Mail</title>
      <link>https://mike.puddingtime.org/posts/2009-01-18-quixotic-appscript-mail/</link>
      <pubDate>Sun, 18 Jan 2009 12:35:32 +0000</pubDate><author>mike@puddingtime.org (mike)</author>
      <guid>https://mike.puddingtime.org/posts/2009-01-18-quixotic-appscript-mail/</guid>
      
      <description>I don’t know why I get into these things.
Below is a script that takes the selected messages in Mail.app and saves them to Yojimbo, which I like a lot for keeping schtuff.
Some things that might have told me to quit and use someone else’s AppleScript instead of rolling my own:
First, I couldn’t …</description>
      <content:encoded><![CDATA[<p>I don&rsquo;t know why I get into these things.</p>
<p>Below is a script that takes the selected messages in Mail.app and saves them to <a href="http://www.barebones.com/products/Yojimbo/">Yojimbo</a>, which I like a lot for keeping schtuff.</p>
<p>Some things that might have told me to quit and use someone else&rsquo;s AppleScript instead of rolling my own:</p>
<p>First, I couldn&rsquo;t figure out how to make rb-appscript work with references between apps.  So the part that grabs the attachment from Mail has no way to say to the part that imports the attachment to Yojimbo, &ldquo;Hey &hellip; this object here is a file.  Deal with it.&rdquo; Instead, the file has to be stowed somewhere then picked up for use by Yojimbo.</p>
<p>Second, Yojimbo can&rsquo;t import everything &hellip; like zip files, for instance. So instead of just doing something to catch exceptions I decided to go and read the MIME types of attachments then check them against an array of legal file types.</p>
<p>On the other hand, I can tag the attachments as they&rsquo;re imported, and this is much faster than dragging the attachments into Yojimbo, because I can tie it to a <a href="http://www.indev.ca/MailActOn.html">Mail Act-On</a> keystroke (and because Mail.app gets really slow with attachment handling sometimes, even if you don&rsquo;t mind mousing).</p>
<p>And there&rsquo;s one other good reason to do stuff like this:  I&rsquo;d rather get the practice with Ruby than crib AppleScript from someone else.   I&rsquo;ll take <code>foo.split(',')</code> over <code>set AppleScript's text item delimiters to &quot;,&quot; </code> any day of the week.</p>
<p>
<p>[sourcecode language=&lsquo;ruby&rsquo;]</p>
<p>!/usr/bin/ruby</p>
<p>require &lsquo;rubygems&rsquo;</p>
<p>require &lsquo;appscript&rsquo;</p>
<p>require &lsquo;mime/types&rsquo;</p>
<p>require &lsquo;osax&rsquo;</p>
<p>include OSAX</p>
<p>include Appscript</p>
<p>mail = app(&ldquo;Mail&rdquo;)</p>
<p>yoj = app(&ldquo;Yojimbo&rdquo;)</p>
<p>tmpdir = &ldquo;/Users/mph/tmp&rdquo;</p>
<p>legal_files = [&ldquo;image/gif&rdquo;, &ldquo;image/jpeg&rdquo;, &ldquo;application/pdf&rdquo;, &ldquo;image/png&rdquo;, &ldquo;application/word&rdquo;,&ldquo;text/plain&rdquo;, &ldquo;application/msword&rdquo;, &ldquo;text/html&rdquo;]</p>
<p>messages = mail.selection.get</p>
<p>messages.each do |m|</p>
<p>m.mail_attachments.get.each do |a|</p>
<pre><code>tmpfile = &quot;{tmpdir}/{a.name.get}&quot;



a.save(:in =&gt; tmpfile)

type = MIME::Types.type_for(tmpfile)[0]



if legal_files.include?(type)

  yoj.import(tmpfile)

  item = yoj.database_items.last

  taglist = osax.display_dialog(&quot;Enter tags for {a.name.get}&quot;, :default_answer =&gt; &quot;&quot;, :buttons =&gt; ['Cancel', 'Okay'],  :default_button =&gt; 2, :with_icon =&gt; :note).fetch(:text_returned).split(&quot;,&quot;)

  

  taglist.each {|t| item.add_tags(t)}

else

  osax.display_dialog(&quot;Yojimbo can't import {a.name.get} - (filetype: {type})&quot;, :with_icon =&gt; :stop)

end



File.delete(tmpfile)



end
</code></pre>
<p>end</p>
<p>[/sourcecode]</p>
</p>
<p>#applescript #appscript #mail #ruby #yojimbo</p>
<p><em><a href="mailto:mike@puddingtime.org?subject=Re%3A%20Quixotic%2C%20Appscript%2C%20Mail">Drop a line about this</a>.</em></p>]]></content:encoded>
    </item>
  </channel>
</rss>
