Inserting DT note with Ruby

I am playing with importing Kindle clippings into DevonThink. I know there is already an AppleScript that does that, but it works from the clippings on the web, which only shows clippings from books you have purchased through Amazon, not from PDFs you have converted yourself (my main use of it as a student). So I will work from the My clippings.txt file.

I would like to do it in Ruby, since that is what I know well, and it gives me a lot of powerful text wrangling power. I am new to apple scripting through Ruby, but there are some good tutorials, and anyway the only command I really need is to create a folder, and insert some notes, so it shouldn’t be too hard.

I was able to access the DevonThink object, create a folder etc, but cannot insert a note. The Apple script that works (I tested it) is:

tell application "DEVONthink Pro"
	create record with {name:"Test", type:rtf, content:"Hello"}
end tell

ASTranslate renders this as:

app("DEVONthink Pro").create_record_with({
    :content => "Hello",
    :type_ => :rtf,
    :name => "Test"

However, this gives me

irb(main):035:0> app("DEVONthink Pro").create_record_with({
irb(main):036:2*     :content => "Hello",
irb(main):037:2*     :type_ => :rtf,
irb(main):038:2*     :name => "Test"
irb(main):039:2> })
ArgumentError: Unknown keyword parameter: :content
        from /Library/Ruby/Gems/1.8/gems/rb-appscript-0.5.3/lib/appscript.rb:467:in `_send_command'
        from /Library/Ruby/Gems/1.8/gems/rb-appscript-0.5.3/lib/appscript.rb:464:in `each'
        from /Library/Ruby/Gems/1.8/gems/rb-appscript-0.5.3/lib/appscript.rb:464:in `_send_command'
        from /Library/Ruby/Gems/1.8/gems/rb-appscript-0.5.3/lib/appscript.rb:643:in `method_missing'
        from (irb):35

I have tried a bunch of different versions, as well as reading the documentation for Appscript etc, but could not get any further. Any help would be very appreciated. Any future script will be shared with this community.


Hi Houshang-

I believe you need to have the “location” argument specified as empty, as opposed to considering it optional. Anyway, this works for me:

I stopped using Ruby a while back, so I don’t know I can continue answering your questions this easily, but if you’d consider Python, I could assist.

Best wishes, Charles

Brilliant, that did it. Thanks a lot!


Great Stian!

I think this is the issue:


Best wishes, Charles