2007/12/22

iTunes-playlist-output.xml

iTunesplaylistを選択-iTunesメニュー-ファイル-書き出し-Unicodeテキスト
を選択した結果のテキストどれも全く気に入らないので、XML書き出したのを整形。

# 自分で作成した playlist の曲をよみやすいテキストに書き出す.一歩手前
# playlist.rb

require 'rexml/document'

class BaseXML

  attr_accessor :doc

  def initialize(path=nil)
    @doc = readxml(path) unless path.nil?
  end

  def readxml(path)
    return nil unless FileTest.exist?(path)
    return REXML::Document.new(IO.read(path)) unless path.nil?
  end

  def key?(xpath)
    return true unless @doc.root.elements[xpath].nil?
    return false
  end

  def lookup(xpath)
    return nil unless key?(xpath)
    if @doc.root.get_elements(xpath).size == 1
      @doc.root.elements[xpath]
    else
      @doc.root.get_elements(xpath)
    end
  end

end

def one(song)
  h = Hash.new
  begin
    song.each{|x| h[x.text] ||= x.next_element.text}
  rescue
  end
  trackID = h['Track ID']
  @playlist[trackID] = [h['Name'], " / ", h['Album'], " -", h['Artist']]
end

@playlist = Hash.new
xml = BaseXML.new('output.xml')
list = xml.lookup('dict/dict/dict').each{|k| }
list.each{|x|
  song = x.to_a.select{|i| i.class.to_s =~ /REXML::Element/}
  one(song)
}

iid = xml.lookup('dict/array/dict/array/dict/integer')
iid.select{|x| x.class.to_s =~ /REXML::Element/}
iid.each{|x|
  print @playlist[x.text]
  print "\n"
}
exit

% /usr/local/bin/ruby playlist.rb > output.txt


+++ memo +++

iTunes-ファイル-書き出し が書き出す XML の特徴。

document root からたどって <dict><dict> の配下にある <dict> 要素におさめられているのが一曲分。
一曲分の要素は <key>or<integer>or<string> のいずれかで構成されている。

 <dict>
 <key>Track ID</key><integer>2314</integer>
 <key>Name</key><string>イエロー・マジック・カーニバル</string>
 <key>Artist</key><string>Van Dyke Parks</string>
 <key>Composer</key><string>細野晴臣</string>
 <key>Album</key><string>細野晴臣トリビュート・アルバム Tribute to Haruomi Hosono [Disc 1]</string>
 <key>Genre</key><string>ポップ</string>
 <key>Kind</key><string>AAC オーディオファイル</string>
 ...
 </dict>


例えば、doc.root.elements['dict/dict/dict/Artist'] としても ”Van Dyke Parks” は得られないから
h['Artist'] で呼び出しができるように一旦ハッシュにした。

xpath='dict/array/dict/array/dict/integer'には曲固有のID番号がふってある。path='dict/array/dict/array/dict/integer'の'integer' 要素の順番が曲順であって
xpath='dict/dict/dict'の順番とは無関係。

--imported_from
http://www.midore.net/daybook/2007/12/1198249205.html

2007/12/18

Leopard-Ruby

Security Update 2007-009 に Ruby update が含まれていた

Security Update 2007-009

% ruby -v
ruby 1.8.6 (2007-09-24 patchlevel 111) [universal-darwin9.0]


--imported_from
http://www.midore.net/daybook/2007/12/1197975605.html

2007/12/16

Leopard-QuickTime

このさい QuickTime 関連のインターネットプラグインおふって QuickTime.app も使用しないように。

% cd /Library/Internet Plug-Ins
% sudo chmod 600700 QuickTime*
% sudo chmod 600700 /Applications/QuickTime Player.app

Safari -環境設定-ジャバスクリプト にチェックをいれて、
ヘルプーインストール済みプラグイン を表示. QuickTime 関連のプラグインがなくなっているのを確認

OS X ソフトウエア・アップデートが出たときのことを考えていなかったのを反省し修正。datetime='2007-12-18T21:32:59+09:00'
--imported_from
http://www.midore.net/daybook/2007/12/1197730805.html

2007/12/10

Leopard-Spotlight

スポットライトをオフる

http://www.macosxhints.com/article.php?story=20071102215912892

/System/Library/LaunchAgents/com.apple.Spotlight.plist
/System/Library/LaunchDaemons/com.apple.metadata.mds.plist

とありました。

% sudo launchctl unload -w  /System/Library/LaunchAgents/com.apple.Spotlight.plist
% sudo launchctl unload -w  /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

とした。

さらに
http://www.macosxhints.com/article.php?story=2007103015513360

sudo chmod 0 /System/Library/CoreServices/Spotlight.app
To re-enable it later, do this:
sudo chmod 755 /System/Library/CoreServices/Spotlight.app


実行するとファインダーのメニューバーから虫眼鏡アイコンなくなりすっきりした。

+++

追記:スポットライトをオフると書いたとおり上記を実行するとスポットライト機能が停止します。言うまでもないことですがこの意味が分からない人は実行すべきではないでしょう。また同時に、find や grep コマンドを利用したことのない人や find って何?という人も上記のコマンドを実行すべきではないでしょう。
個人的には find (詳細は % man find ) を利用していてなんら不足はなく Spotlight を使用していなかった為 www.macosxhints.com にあった内容はとても有益でした。

ターミナルを起動したことがない人や普段コマンドを利用してない人が、スポットライト機能を抑制したい時に最初に行うべき操作は、システム環境設定->Spotlight->プライバシーを開いて抑制したいディレクトリやハードディスクを指定したり、Spotlight->検索結果を開いて検索結果に表示されるカテゴリを制御すること、かもしれません。もちろん公式な情報が知りたければ当然ながらアップルに電話してサポートをお願いするべきです。

ちなみに、なにかの間違いで上記のコマンドを実行してしまいスポットライト機能を停止させてしまった場合、再びもとの状態に戻すには
Applications->Utilities->Terminal.app を起動し下記のコマンドを実行しコンピュータを再起動。管理者権限を有するユーザで実行する必要があります。launchctl コマンドの詳細は % man launchctl とすると表示されます。

% sudo launchctl load -w  /System/Library/LaunchAgents/com.apple.Spotlight.plist
% sudo launchctl load -w  /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
% sudo chmod 755 /System/Library/CoreServices/Spotlight.app


% は単なる記号です。打ち込む必要はありません。

--imported_from
http://www.midore.net/daybook/2007/12/1197212405.html

+++ 追記 +++
2010-02-06

関連する記事
10.6.2 Spotlight OFF
"Leopard"ラベルがついた全ての記事

2007/12/02

音楽の力

DVDタイトル名そのままの充実した内容だった。

ISBN: B000NA7WTE

--imported_from
http://www.midore.net/daybook/2007/12/1196521205.html

2007/11/28

The Art of UNIX Programming

この秋に買った本。

ISBN: 9784756149480

私にとっては今年最高の一冊となりそう。

最初の方、歴史的な話はぐいぐいと引き込まれるように読めてしまう。
真ん中へんあたりには(私の場合)ちょっと難しい話もあったものの、コンピュータと名のつくものに触れる全ての人にとって大事なことがいっぱい書いてあった。最後の方には Macintosh ユーザについて鋭い指摘がありとても興味深いことが書かれてある。
最後の最後、foo が「不宇」だったりする禅問答には正直驚いてしまった。衝撃的といってもいい。

どちらかといえば Tillie 伯母さん(ページ516参照)の側に近いエンドユーザである私にとってはなにもかもが新鮮だった。

--imported_from
http://www.midore.net/daybook/2007/11/1196175612.html

+++ 追記 +++
2010-02-06

関連する記事
Snow Leopard creator code

2007/11/13

あれこれ検索

•Leopard で MySQL や アダプタをちゃんと動かすための方法が紹介されていた。
[Hivelogic - The Narrative - Installing MySQL on Mac OS X]
インストール用の shell もダウンロードできるようだ。

•Leopard firewall についてのお話。
http://www.heise-security.co.uk/articles/98120

/var/log/ipfw.log

から

/var/log/appfirewall.log

にかわったそうだ。

•google News で知った。Leopard のトロイの木馬 OSX.RSPlug.A
http://www.macworld.com/2007/10/firstlooks/trojanhorse/index.php

•私と同じような失敗した人を発見してひそかに共感。その後の追求は私などとは段違いにすばらしぃ。
http://fluctisonous.com/2007/11/8/where-has-my-gem_server-gone

> My first mistake was to think that the usual;


--imported_from
http://www.midore.net/daybook/2007/11/1194946625.html

AppleScript Release Notes for Mac OS X version 10.5

AppleScript 2.0 についてのリリースノートがでていた。
http://developer.apple.com/releasenotes/AppleScript/RN-AppleScript/index.html

ユニコードを完全にサポートしました、だから at:'2007-11-16T00:10:16+09:00' サポート.
as text、as string、as Unicode text これら3つの結果は同じになるよ
とか、
コメントにシャープを使えるようになったから、#!/usr/bin/osascript と書けるよ
などなど掲載されてた。

んでは早速、シャープでコメント入れたりしてみる。3つが同じ結果かどうかも。

# なにもつけてない。
set jp to "そのままの日本語"
# as text。
set txt to "日本語 as text " as text
# as string。
set str to "日本語  as string" as string
# as Unicode text。
set ujp to "日本語 as Unicode text" as Unicode text
return {jp, txt, str, ujp}
=> {"そのままの日本語", "日本語 as text ", "日本語  as string", "日本語 as Unicode text"}


ディスプレイダイアログは?

#tell application "Finder"
# なにもつけてない。
set jp to "そのままの日本語"
display dialog jp buttons {jp}
#end tell
=>{button returned:"そのままの日本語"}


意地悪して tell app "finder" もとってみたけど、ディスプレイダイアログの文字列も文字化けしてないしボタンで選択した文字列も大丈夫.わー!ひょっとしてひょっとしてこのような書き方できるのってOS 9 以来なのでは?
...と思ったけれど、試し方としてはこれでいいか若干自信なし...あっ、文字によっては問題あるのかな。

is in も?

#tell application "Finder"
  display dialog "Select" buttons {"キャンセル", "foo", "日本語"} default button 1
  set ans to button returned of result
  return "日" is in ans
#end tell
=> true

大丈夫みたい。is in ってこうやって使うんだったっけ?自信なし

--imported_from
http://www.midore.net/daybook/2007/11/1194946629.html

2007/11/01

あれこれ google 検索

OS X 10.5 AirPort Interface がらみ

http://discussions.apple.com/thread.jspa?messageID=5676352&#5676352
同じ症状が出た人みつけてうれしい。っほ。

OS X 10.5 gem
http://discussions.apple.com/thread.jspa?messageID=5668663&#5668663
gem アップデートしてパスがかわっても動揺しないで
export GEM_HOME="/Library/Ruby/Gems/1.8"
export GEM_PATH="/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8"
しなさいって言ってる人いました。

http://rubyforge.org/pipermail/rubygems-developers/2007-October/003112.html

OSX 10.5 patches
英語力 & 技術力 & 読解力不足で理解不足...
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/12895
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/12901
http://chopine.be/lrz/ruby-osx-patches
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/32160
http://rubyforge.org/pipermail/rubygems-developers/2007-October/003115.html
#Appleの方?がなにかを準備すると読み取れるものの...よくわかりません。この告知は
http://trac.macosforge.org/projects/ruby/wiki/Troubleshooting#IcannotbuildrubymysqlonLeopardwithmysql.combinaries

Leopard リリース後のこの告知につながってるのかな?

--imported_from
http://www.midore.net/daybook/2007/11/1193924914.html

2007/10/31

Leopard AirPort interface

OS X 10.5 インストールしていろいろ設定し終えてから
/var/log/system.log をみたら

SystemUIServer[102]: Error: ACInterfaceCreate() no AirPort interface found for en1

が、system.logを埋め尽くしていた。びっくりした。慌てて再起動。ログインして再びログをみにいくと、さっきErrorはとまっていた。あーよかった。なんだったんだ?
なんか一時的におかしかったんだろなーっと、お茶いれよう。とスリープさせた。

で、スリープから復帰。system.log みたら、げー立派に再現してるじゃないの!よくみてると、ほぼ10秒に一度の頻度でこのログはきまくってるし。こうしてみてる間にもどんどんログ増えていくばかりなのでシステム終了。うむー。スリープしたのがいけなかったわけ?
どしたものかな。と。

もう一度、ログイン後すぐスリープしてすぐスリープから復帰すると、みごと再現した。ビンゴなのはわかったんだけど、スリープ周りって誰が管理しているの?とかさっぱりわからないし、とにかくどのプロセスを終了させる術がわからなくて一時は再度インストールか?なんて悩んでこの文字列をじっーっとみてたら、わかった!。

そもそも、私はネットワーク環境設定で eth1 の airmac interface 自体を削除してました。そのくせ削除する直前に「メニューバーにAirMac の状況を表示」のチェックをいれてたんでした。
これがいけなかったんだろ。と
プラスマークをクリックして airmac interface を登録していったん適用してから
「メニューバーにAirMac の状況を表示」の「チェック」を外した!
これでどうよ?と system.log みたらぴたりと止まった。やった!。あーよかった。

memo
ネットワーク環境設定で AirMac interface を登録(プラスマークで)していない時は、メニューバーにAirMacの状況を登録しない、が吉。と。

こんなことになったのはきっと私の日頃の行いが悪いからなのかも。

--imported_from
http://www.midore.net/daybook/2007/10/1193840657.html

2007/09/05

RubyOSA Finder

rubyosa-0.4.0 で Finder アイテムを獲得する奴の書き直し
http://www.midore.net/daybook/2007/04/1176460414.html

require 'rbosa'
OSA.utf8_strings = true
finder = OSA.app('Finder')

def folds(fold)
  print "Folder #{fold.name}\n"
  return nil if fold.get.items.empty?
  # if fold.get.items.size >= 20

  fold.get.files.each{|i| puts "File  #{fold.name}/#{i.name}" }
  fold.get.items.each{|i| folds(i) if i.get.class.name == "OSA::Finder::Folder" }
end

def desktopitems(obj)
  obj.each{|x|
    case x.get.class.name
    when /Disk/ : print "Disk:: #{x.name}\n" # need HDD mount
    when /Folder/ : folds(x)
    when /File/ : print "File  #{x.name}\n"
    end
  }
end

print "==Desktop's Folders and Files==\n"
desktopitems(finder.items)
print "==" 


結果
==Desktop's Folders and Files==
File finderitems.rb
File get_properties.rb
File rbosa_finder.txt
Folder xxx
File xxx/1.txt
Folder zzz
File zzz/hoge.rb
Folder ddd
File ddd/finder.rb
File ddd/untitled.rb
Folder 名称未設定フォルダ
==

++ memo ++
システム環境 セキュリティーFileVault 「切」にしていないと RubyOSA 動かない。

OS X 10.4.10 FInder.app Version

tell application "Finder"
  version
end tell

# => "10.4.7"

--imported_from
http://www.midore.net/daybook/2007/09/1188965456.html

+++ 追記 +++
2010-02-06

関連する記事
"RubyOSA"ラベルがついた全ての記事

2007/06/30

Book class for amazon

amazon 用のbook クラス考。テキストの中に isbn を探す始まるマークがみつかったら、Book クラスを呼び出す。
ItemLookup でamazon からのレスポンス XML は、Search で得られる結果とは異なり <Items><Item> 要素は1つ。指定したISBN がなければエラーXMLが返ってくる。

  item = Book.new(amazonxml).setup.item


amazon からのレスポンス xml を Book クラスに対して Book.new(xml) し...setup.item すると、Book の Struct で指定された要素を拾う。拾いたい要素のフルパスをコード内に記述しない方法の模索。

仮に<small><url>... <big><url>... といったように異なる親要素を持つ同一名の要素が レスポンス xml内 にあった場合で、
<big>要素の<url>要素 を拾いたい時、Book の Structに big_url とアンダーバーで要素名を連結するとその要素パスにマッチしたデータを探す。

Book クラス @h の中身は、{ [アマゾンXML の要素フルパス]=> 要素のテキスト ...]

#require 'time'
#require 'uri'
#require 'net/http'
#require "rexml/document"

class Book < Struct.new(:mediumimage_url, :detailpageurl, :author, :isbn, :publisher, :publicationdate, :title, :listprice_amount)

  def initialize(xml=nil)
    @getxml = REXML::Document.new(xml)
    #@tplxml = Tpl.new().tplamazon
    str = '<?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type="text/xsl" href="amazon.xsl"?>
    <docroot>
      <link rel="alternate" type="text/html" href="http://www.midore.net/"/>
      <modified/>
      <Items/>
    </docroot>'
    @tplxml = REXML::Document.new(str)
    @h = Hash.new
  end
  
  def errorcheck
    @tplxml = nil
  end

  def setup
    get_ele() if @h.empty?
    @h.each{|k,v|
      members.select{|x| self[x] = v if k.downcase.include?(x)}
    }
    #unless detailpageurl.nil?
      #durl = detailpageurl.scan(/\/.\/ASIN\/.*?%/).last.gsub("%",'') 
      #self.detailpageurl = 'http://www.amazon.co.jp' + durl
    #end
    return self
  end
  
  def item
    return nil if @tplxml.nil?
    item = REXML::Element.new('item')
    each_pair{|k,v| 
      item.add_element(k.to_s).add_text(v.to_s)
    }
    return item
  end

  def get_ele(ele=nil)
    ele = @getxml.root if ele.nil?
    errorcheck if ele.to_s.include?('Error')
    return nil if @tplxml.nil?
    ele.each{|x| 
        get_ele(x.entries) if x.has_elements?
      @h[x.xpath.to_s.gsub("/", '_')] ||= x.text unless x.text.nil?
      }
  end

end 

p Book.new(amazonxml)
#<struct May::AmazonAWS::Book mediumimage_url=nil, detailpageurl=nil, author=nil, isbn=nil, publisher=nil, publicationdate=nil, title=nil, listprice_amount=nil>

p item = Book.new(amazonxml).setup.item
item 要素に自分が欲しい要素だけを集めてある。
<item> ... </>

最終的な item 要素の中身

<item>
<mediumimage_url/>
<detailpageurl/>
<author/>
<isbn/>
<publisher/>
<publicationdate/>
<title/>
<listprice_amount/>
</item>


問題点 :
1, 著者が複数だった場合はどうする?
2, 画像サイズ指定し忘れた。
3, 表示させる要素に ISBN or EAN を含めるべきかどうか。その他、etc

--imported_from
http://www.midore.net/daybook/2007/06/1183167964.html

パズルパレス

ダビンチコードを書いた Dan Brown の初期の作品

ISBN: 4047915173

1998 年に書かれたもの。日本では2006年が初版。
トランスレータという巨大な暗号解読機械をめぐっておこる脅迫事件。
この作者がいかに暗号好きかを察することができる。
ストーリが大どんでん返しで終わるのも、テレビをみているかのような画面切り替えのような描写方法も、この頃から使われていたのだな、とわかった。

--imported_from
http://www.midore.net/daybook/2007/06/1183161318.html

2007/06/29

芥川龍之介

「没後80周年特別企画」と帯に書かれてあった。現代の芥川賞、直木賞作家らのエッセイつき。

ISBN: 4796656774

++ 収録作品 ++
蜘蛛の糸
杜子春
羅生門

芋粥
半巾
戯作三昧
地獄編
奉教人の死
きりしとほろ上人伝
蜜柑
魔術

秋山図
薮の中
トロッコ
玄鶴三房
河童
歯車
或阿呆の一生

この本の中で、作品「半巾」について平野敬一郎氏は、
「...芥川的なアイロニーのあり方が、初期において最も端的に描かれた作品...」
と述べている。

文学的テキストから受ける印象は人によって非常に千差万別なので、人それぞれ感じ方が違って当然なのだけど、面白いことに、同じ作品であっても感情が炸裂したかのような激情的な文章だという印象を受ける人もいれば、非常に冷徹で知的クールな文章だという印象を受ける人もいる、、、。まるで違う作品を読んだかのごとく。

芥川作品はまるで短距離走者のようだとどこかに書かれていたが、実際「単語」ひとつひとつに対してかなり熟考したのかもしれない、とみうけられなくもない。でもそれは読者の勝手な憶測なのかもしれない。それほど考えて書いた訳じゃないよと本人は云うかもしれない。
どちらだったにせよ、その単語を選んだという事実を眺めてみた時、芥川作品全般に流れる心の痛みに思いをはせてしまう。

河童は、中学生の時に読んでいたにも関わらず初めて読むような気がした。
読むべき対象年齢があるのかも?と思った。一定の年齢に達してからでないと、かなわない作品だったのかもしれない。。。じゃ、対象年齢て何?などと考えていたら、実は私のつまらん思い込みで読むべき対象年齢なんて実は「ない」のかもしれない。

途中、作者の怒りにまかせて溢れてくる鋭利な刃物のような単語のつらなりを感じた。怒れば怒るほどに、クールに的確に相手を論破できる人っているんだよなーと思う。そういう人物像を連想させられた。
と、おもいきや、作者のメンタリティはもっともっと違うところにもあるようにも読めてくるから面白い。

--imported_from
http://www.midore.net/daybook/2007/06/1183127623.html


+++ 追記 +++
2010-02-06
midorex.blogspot.com に import するにあたって

今、この本に収録されている作品の中で一番印象深いものをあげよといわれたら「半巾」かな。
短編であれ小説であれ、読んだことを忘れた頃、おもむろに開いたページを読んだその瞬間に鮮やかな何かを瞬時に読者の心に再現させてしまう作品ってある。しかもその再現は時間軸とともに微妙に変化し読む側はそれをはっきりと意識せざるをえないので、読者は何度も新鮮な読書ができてしまうの。

2007/06/06

Amazon Web Services 2

昨日作ったやつの答え合わせのつもりで検索検索。

natu_nの日記

Amazon ECS (Ver.2007-01-15) のドキュメント

Docs: Amazon E-Commerce Service (API Version: 2007-01-15)

ISBN(国際標準図書番号)規格改定に伴うアソシエイト・リンクの対応について [追加情報]

げげ?ISBNが13桁に?

ISBN(国際標準図書番号)規格改定等について お知らせ

(1) 2007年以降ISBNの規格は13桁とし、流通コードの国際標準であるEANコード(わが国ではJANコード)と一致させる。
http://www.isbn-center.jp/whatsnew/kikaku.html
(5) 2007年以降、現行のISBNは無効となる。


Type of product ID you are requesting information about.ISBN is for looking up books by their ISBN number. So, the ItemId must be a valid ISBN number and the search index in the request must be Books or ForeignBooks. The ISBN value must be 13 digits long and cannot include hyphens. The older 10-digit ISBN numbers can be converted in to the new 13-digit version by prepending "978" to the 10-digit ISBN number, which makes it 13 digits long.SKU requires a MerchantId. US only.UPC is US only.EAN is the same as JAN (Japanese article number), so you may use this parameter to look up items by JAN or EAN. DE/JP/CA only.If you select SKU, UPC, or EAN as the IdType for your request, you also need to include the SearchIndex parameter.


translation に頼ってみる。

ISBNは、彼らのISBN番号によって本を調べることに賛成です。それで、ItemIdは有効なISBN番号でなければなりません、そして、要請の検索インデックスはBooksまたはForeignBooksでなければなりません。ISBN価値は長さ13桁でなければならなくて、ハイフンを含むことができません。以前の10桁ISBN番号は10桁ISBN番号に「978」を前に付加することによって新しい13桁バージョンに中で変わることができます。そして、それはそれを13桁長くします。SKUは、MerchantIdを必要とします。USだけ。UPCは、USだけです。EANはJAN(日本の記事番号)と同じですので、あなたはJANまたはEANによってアイテムを調べるためにこのパラメータを使うかもしれません。DE/Japan paper/CAだけ。あなたがSKU、UPCまたはEANをあなたの要請のためのIdTypeとして選ぶならば、あなたもSearchIndexパラメータを含める必要があります。


2007 年以降は国際標準 EANだって読んだんだから、IdType=EAN を追加して実行してみると。

Result_ IdType=EAN # ISBN-13:9784797336610

リクエストには必要なパラメータの組み合わせが含まれていません。IdTypeがEANである場合、SearchIndexが必要です。


あっ、SearchIndex パラメータが必要だと書いてあったんだった。

> 検索インデックスはBooksまたはForeignBooksでなければなりません


公式ドキュメント_ SearchIndex

The Amazon store to search. Do not use this parameter with ASIN searches; an error will be returned.SearchIndex is required any time you select SKU, UPC, or EAN as the IdType for your request. The list of available SearchIndex values, segmented by locale, can be found on the search index values page.If IdType is set to EAN, SearchIndex is restricted to a select group of values by locale (Amazon.de and Amazon.co.jp).


やくす

捜すアマゾン店。ASIN検索でこのパラメータを使わないでください;エラーは返されます。あなたがSKU、UPCまたはEANをあなたの要請のためのIdTypeとして選ぶどんな時でも、SearchIndexは必要です。利用できるSearchIndex価値(現場によって分割される)のリストは、検索指数値ページで見つかることができます。IdTypeがEANにセットされるならば、SearchIndexは現場(Amazon.deとAmazon.co.jp)によって選ばれたグループの値に制限されます。


捜すアマゾン店。笑
「SearchIndexは現場(Amazon.deとAmazon.co.jp)によって選ばれたグループの値」てなんだろ。

Search Index Values
http://docs.amazonwebservices.com/AWSEcommerceService/2007-01-17/ApiReference/SearchIndexValues.html

SearchIndex=Books で試す。

Result_ IdType=EAN, SearchIndex=Books # ISBN-13: 9784797336610

9784797336610は、ItemIdの値として無効です。値を変更してから、再度リクエストを実行してください。

10桁ならとおる?
Result_ IdType=EAN, SearchIndex=Books # ISBN-10: 4797336617

4797336617は、ItemIdの値として無効です。値を変更してから、再度リクエストを実行してください。


おかしい。

公式ドキュメント_ItemId

Product(s) you would like information about. You may specify up to ten IDs using a comma-separated list (REST) or multiple elements (SOAP). By default the item IDs are assumed to be ASINs, unless you specify the IdType parameter.


やくす

あなたが情報が好きだろう製品(s)。あなたは、コンマで区切られたリスト(REST)または複数の要素(SOAP)を使用している最高10のIDを指定するかもしれません。あなたがIdTypeパラメータを指定しない限り、デフォルトで、アイテムIDはASINsであるとされます。


ItemId はIdTypeで指定されたTypeになると。何も指定しない時は ASIN になるよと。
IdType=EAN と指定したら必ずSearchIndexが必要と。その通りにしたつもりなんだけどな。Books じゃいけないのかなー。

どうすればいいのー?> google

実験結果をわかりやすくまとめてくださってました!。すばらしぃ!
HekatonCarefuleな日記

IdType=ISBN, SearchIndex=Books で13桁のISBNを指定したら成功とのこと。
13桁の ISBN を利用するには今のところ(2007/06) IdType=ISBN を指定する必要があるってことなんだね。EAN は使えないのかな。

Amazon Web Services Resource Center で検索
http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=59

http://developer.amazonwebservices.com/connect/entry.jspa?externalID=765&categoryID=17

The EAN field does not support ISBN-13 in the JP locale.


うわわ。IdType=EAN が指定できないのは日本ローカルな問題!?? だったのか。そか。そーだったのか。

日本のアマゾンさんは、なんでこの問題を日本語で明記してないのかなぁ。それとも私の探し方がたりないのかな。
「HekatonCarefuleな日記」さんが書かれているような内容は日本アマゾンの公式なページに掲載されていてしかるべき内容だと思うんだけど。あんのかなぁ。

+++++++++++++++++++++++++++++
まとめ。これでリクエストすれば13桁で検索できました。

        "Service=AWSECommerceService",
        "AWSAccessKeyId=#{@aws_key}",
        "Operation=ItemLookup",
        "ItemId=#{isbn}",
        "IdType=ISBN",
        "SearchIndex=Books",
        "AssociateTag=#{@aws_id}",
        "ResponseGroup=Medium"

けど、ISBN-10桁の本の情報を得たい時にはこれだとエラーになってしまうんでプログラム側でISBN桁数をみてからパラメータを分岐させるようにしないといけないということになりそ。
+++++++++++++++++++++++++++++

あらためて情報収集

本出している有名な方。Perl で書かれてありました。やっぱりパラメータはHekatonCarefuleな日記さんと同じでした。
Amazon Web Servicesを使ってISBN-13からASINを取得するPerlプログラム
http://d.hatena.ne.jp/hyuki/20070123#isbn

おや!?
"Version=2007-01-15" ひょっとしてひょっとしてこれを追加すれば10桁も可能になったりして?...それはありませんでした。
Result_ IdType=ISBN, SearchIndex=Books # ISBN-10: 4797336617

4797336617は、ItemIdの値として無効です。値を変更してから、再度リクエストを実行してください。


上級者の方発見。ちゃんとISBN 桁数で条件分岐もあるしエラーチェックもあってすごいです。答え合わせの答えが見つかった感じがしました。
http://www.iwazer.com/~iwazawa/diary/archives/003010.html
Version => '2007-05-14', ってかいてあった。あとで調べてみよう。

Amazon Web Services Resource Center
http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=59

Thread: 2007年からの和書のASINについて
http://developer.amazonwebservices.com/connect/thread.jspa?threadID=12010&tstart=0

--imported_from
http://www.midore.net/daybook/2007/06/1181131399.html

2007/06/05

Amazon Web Service

Amazon Web Service に ISBN で問い合わせしてみる。

登録IDの取得
http://www.amazon.co.jp/gp/feature.html?docId=451209

オンラインドキュメントトップページ
http://www.amazon.com/gp/browse.html/?node=3487571

オンラインドキュメントトップページから迷子になった後にやっとたどり着いたページ
http://docs.amazonwebservices.com/AWSEcommerceService/2007-02-22/

問い合わせ先:ecs.amazonaws.jp
目的のXML :
Medium Response Group
http://docs.amazonwebservices.com/AWSEcommerceService/2007-02-22/ApiReference/MediumResponseGroup.html

獲得したい情報:

URL
表紙URL
著者名
ISBN
出版社名
出版日付
タイトル
価格

# isbn_lookup.rb
=begin
The Base URL
# http://docs.amazonwebservices.com/AWSEcommerceService/2007-02-22/PgRestRequestsArticle.html
# For Amazon.co.jp (JP) => http://ecs.amazonaws.jp/onca/xml?Service=AWSECommerceService

ItemSearch Operation
# http://docs.amazonwebservices.com/AWSEcommerceService/2007-02-22/ApiReference/ItemSearchOperation.html

Medium Response Group
# http://docs.amazonwebservices.com/AWSEcommerceService/2007-02-22/ApiReference/MediumResponseGroup.html>

The Request that Generated the Response (REST)

http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService
# http://ecs.amazonaws.jp/onca/xml?Service=AWSECommerceService
    &AWSAccessKeyId=[Your Access Key ID Here]
    &AssociateTag=[Your Associate ID Here]
    &Operation=ItemLookup
    &ItemId=B00008OE6I
    &ResponseGroup=Medium
=end

require 'uri'
require 'net/http'
require "rexml/document"

module Amazon

  class ISBN_Lookup

    def initialize(aws_accessKeyId, associate_ID)
      @aws_key = aws_accessKeyId
      @aws_id = associate_ID
      @jp_ecs = 'http://ecs.amazonaws.jp'
    end

    def seturi(isbn)
      uri = URI.parse(@jp_ecs)
      uri.path='/onca/xml'
      q = [
        "Service=AWSECommerceService",
        "AWSAccessKeyId=#{@aws_key}",
        "Operation=ItemLookup",
        "ItemId=#{isbn}",
        "AssociateTag=#{@aws_id}",
        "ResponseGroup=Medium"
      ]
      uri.query = q.join("&")
      return uri
    end
  end

  class Access

    def initialize(uri)
      @host = uri.host
      @request = uri.request_uri
    end

    def error_message
      print "SocketError\n"
    end

    def reponse
      begin
        Net::HTTP.start(@host) { |http|
          response = http.get(@request)
          return response.body
        }
      rescue SocketError, error_message
      end
    end
  end

  class Book < Struct.new(:detailpageurl, :mediumimage_url, :author, :isbn, :publisher, :publicationdate, :title, :amount)

    def initialize(res)
      @doc = REXML::Document.new(res) unless res.nil?
      @itemAttributes = @doc.root.elements['Items/Item/ItemAttributes'] unless res.nil?
    end

    def setup
      return nil if @doc.nil?
      return nil if @itemAttributes.nil?
      @itemAttributes.to_a.each{|x| 
        xx = x.name.downcase
        self[:amount] = x.text('Amount') if xx.to_s == "listprice"
        unless members.index(xx.to_s).nil?
          sym = xx.to_sym  #symbol
          self[sym] = x.text
        end
      }
      self.detailpageurl = urldegital
      self.mediumimage_url = urlimg
      return self
    end

    def get(xpath)
      @doc.root.elements[xpath].text unless @doc.root.elements[xpath].nil?
    end

    def urldegital
      get('Items/Item/DetailPageURL')
    end

    def urlimg
      get('Items/Item/MediumImage/URL')
    end

  end

end

#+++++++++++++++++++++++++
#example;

# ISBN :4063406482
aws_key = xxxxxxx 
aws_id = xxxxxxx

isbn = '4063406482'
uri = Amazon::ISBN_Lookup.new(aws_key, aws_id).seturi(isbn)
res = Amazon::Access.new(uri).reponse
book = Amazon::Book.new(res)
p book.setup
#exit
puts book.mediumimage_url
#=> http://ec1.images-amazon.com/images/I/21po5oj5XOL.jpg
puts book.author
#=> 二ノ宮 知子
puts book.isbn
#=> 4063406482
puts book.publisher
#=> 講談社
puts book.publicationdate
#=> 2007-06-13
puts book.title
#=> のだめカンタービレ #18 (18)
puts book.amount
#=> 410


これをもとにエントリーに書籍リンクをはるとこまでが目的。。。

--imported_from
http://www.midore.net/daybook/2007/06/1180989126.html

2007/06/02

mDNS UDP 5353 port

Security Update 2007-005
http://docs.info.apple.com/article.html?artnum=305530-ja

CVE-ID:CVE-2007-2386
mDNSResponder のセキュリティパッチ

mDNSResponder はUDP Port 5353 をローカルネットワークに送信していて、このポートを閉じると印刷できなくなったり、 AirPort などが使えなくなったりするらしい。
らしい、というか実際試してみたらプリンタの存在を認識してもらえなかったし(プリンタにもよるがキューを送信できなくなったりプリンタの存在が見えなくなったり)、AirMacExpress で AirTunes を使うこともできなくなった。

印刷も必要なければ、無線もいらない、意図的にUDP5353ポートを送信させたくない時はある...というか、本来ならばユーザが必要な時にだけ!このポートを送信するという仕様だったらよかったのにな。むやみやたらにまき散らすのでなく。

このポートを操作する方法が下記に簡潔に紹介されていたのでメモメモ。同様のことは mac osx hint でも紹介されていたような気もする。2,3 年前?だったっけ。下記を実行してから netstat -a で確認。

http://www.isskk.co.jp/support/techinfo/general/apple_mac_osx_264.html

パッチをすぐにインストールできない場合は、次のコマンドを使用して、影響を受けるコンポーネントを無効にすることができます。
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

コンポーネントを再度有効にするには、次のコマンドを使用します。
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

このコンポーネントを無効にすると、次のようなその他多くの機能も無効になります。
Auto Discovery での印刷、Airport および Airport Express、AirTune、iTune ミュージックの共有、カレンダー、アドレス ブックなど。


--imported_from
http://www.midore.net/daybook/2007/06/1180750920.html

2007/06/01

疲れた男のユートビア、砂の本から

よみなおし

砂の本 / ホルヘ・ルイス-ボルヘス / 集英社 / 408-773089-1

そんなものは、発明と推理への、たんなる出発点にすぎません。われわれは、学校で懐疑と忘却術を教えられる。とりわけ個人的、ならびに地方的なものを忘れる術です。われわれは連続的な時間のなかに生きています。
...
「私のおかしな過去には」とわたしは言った。「毎日、夕方から朝にかけて事が起こり、それを知らないでいるのは恥だ、という迷信がはびこっていました。
...
「政府はどうなりました?」「言い伝えによれば、次第に廃れました。政府は、選挙を公示し、宣戦し、税金を徴収し、財産を没収し、逮捕を命令し、検閲を課そうとねらいましたが、地球上のだれひとり、従おうとしなかった。...」


痛快だった。今、まさに日本政府は「税金を徴収し」...我らの年金はどこへ?という感じで。^^;
作者は現代人が未来に迷い込んだ設定を施してはるかに遠い未来の社会の有様を未来人に語らせている。未来人はどうやら永久の生をも手に入れたらしい。

ニュースをみたり聞いたりする社会人として常識であるような価値基準を、未来人は「迷信」と断言する。
「情報の遮断」という言葉が思い浮かぶしそれへの価値づけについてぼんやり考えてしまった。昔「情報は取得した後、一度遮断する必要がある」と人に聞いたのを思い出しつつ...

物語中、現代人が自分の生きてきた時代を「おかしな過去」と呼ぶ。政府はどうなったか?なんて、えらく他人事のような質問もする。
私たちが常識と捉えられているシステムや価値観をばっさばっさと cool に斬りたおす。次第に作者が思い浮かべる未来ががひしひしと伝わってきて読みすすむにつれ文字通りのユートピアを満喫できる。が、最後の最後にそのユートピアが抱え込む難題がみえてきて未来にも現代にも共通した爆弾のような何かをみせられ、急に物語は終わる。

ところで作者は「懐疑力を鍛えられる」という文章をどんな気持ちで書いたんだろう。
そういえば、がっこの先生から、なんでもいいから疑問を感じたことを感想文で提出しなさい、と言われたことはあったろうか?疑問を感じないなどとはケシカラン!と叱られたことはあったろうか?疑問をもつことはとても重要です、といった先生のお話しを聞いたことはあったろうか?私の記憶力が衰退しているのを考え合わせたとしても義務教育期間中に懐疑力を鍛えられたことは「なかった」と思う。むしろ、その逆の力を鍛えられたのはよく覚えていたりもするなぁ。と

西暦2007年の日本。今日もどこかで「どうして太陽はおちてこないの?」と口にしてしまった子供がいたとしたら、その瞳は大きく開かれたろうか。それとも、くぐもっただろうか。常識とはなんだろうと考えていたら「ハッカーと画家」を思い出してまた読みなおしてみたくなった。プログラミングの話ではないあたりを。

--imported_from
http://www.midore.net/daybook/2007/06/1180703867.html

+++ 追記 +++
2010-02-06

> 私の記憶力が衰退しているのを考え合わせたとしても

私の記憶力は衰退しているものの
の間違いのようだ。

2007/05/20

ソーシャル・ウェブ入門

『ソーシャル・ウェブ入門―Google、mixi、ブログ…新しいWeb世界の歩き方-滑川-海彦』
という本を読んでいたら、

「砂の本」に「学問の厳密さについて」という謎めいた掌編がある。「帝国と同じ大きさの地図を作る地図職人のギルド」の話で、その帝国では地図づくりが精妙を極めたため、物と対応するような地図づくりが企てられた。


砂の本、わー懐かしい。でも、こんな話あったっけ?ボルヘスの本はこれしか持ってない。けれど、とても印象深かったのを覚えてる。もう何年もずっと本棚の奥にあったはずと、、探してみた。あった!ほこりがついてたので手を洗ってみたりしつつ。早速、目次を探してみたがそれらしきがみあたらない。おかしいな、と紹介本にある ISBN 番号を再度みると微妙にちがっているではないか。アマゾンにいってみてわかりました。私がもってたのはこちらで
http://www.amazon.co.jp/dp/4087730891/

紹介されていたのはこちらだった。
http://www.amazon.co.jp/dp/4087602400/
文庫本もかおうかしら。

--imported_from
http://www.midore.net/daybook/2007/05/1179590425.html

2007/05/19

rubyosa-0.4.0 - iTunes

rubyosa の OSA.app('iTunes') を細分化してみた。

# Created by midore on 2007-05-16.
# 2007-04-25.rb
# ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.9.1]
# rubyosa-0.4.0
# iTunes 7.11

class Song < Struct.new(:song, :name, :artist, :album, :yearr)

  def to_s
   "#{self.name} : #{self.album} (#{self.artist})_#{self.yearr}"
  end

  def self.song
    self.song
  end

end

class SongList

  def initialize(songs=Itunes.new.librarysongs)
    @songs = songs
  end

end
  
class Itunes

  def initialize
    @itunes = OSA.app('iTunes')
  end

  def librarysongs
    songs(obj_library)
  end

  def top25songs
    songs(obj_top25)
  end

  def songs(list)
    ary = Array.new
    list.tracks.each{ |song| 
      ary << Song.new(song, song.name, song.artist, song.album, song.year)
    }
    return ary
  end

  private

  def obj_library
    obj_playlists.find{ |x| x.name == "ライブラリ"}
  end

  def obj_top25
    obj_playlists.find{ |x| x.name == "トップ 25"}
  end

  def obj_playlists
    obj_sources.each { |source| return source.playlists}
    #<OSA::ObjectSpecifierList:0x326004 desired_class=OSA::ITunes::Playlist>
  end

  def obj_sources
    @itunes.sources    #OSA::ObjectSpecifierList
  end

end

require 'rbosa'
OSA.utf8_strings = true

song = Itunes.new.top25songs.first.song
puts song.name
song.play

song = Itunes.new.obj_library.first.song
とすると、
曲はスタートするがウィンドウのカレントの曲を示すアイコンが移動しない。くわえてメニューの現在の曲の情報もみられないのはなぜだろう。

--imported_from
http://www.midore.net/daybook/2007/05/1179559483.html

+++ 追記 +++
2010-02-06

関連する記事
"RubyOSA"ラベルがついた全ての記事

2007/04/13

RubyOSA_0.4.0_OSA::Finder::Folder

RubyOSA_0.4.0 がリリースされてたので試してみました。
http://rubyosa.rubyforge.org/

%cat README
== Requirements ==

Mac OS X 10.4.X or greater
ruby 1.8.X or greater
libxml-ruby 0.3.8 or greater


とのことなので、libxml 0.4 もインストールしてます。
http://libxml.rubyforge.org/index.html

#libxml がインストールされてない場合は、REXML を使うと確かFAQにあったようななかったような気もしつつ...

早速、RubyOSA 0.4.0 Finder用のサンプル。でもなぜか動かないです...

%cat show_desktop.rb
# Lists the content of the Finder desktop.

begin require 'rubygems'; rescue LoadError; end
require 'rbosa'

ary = OSA.app('Finder').desktop.entire_contents.get
ary.each do |x|
    next unless x.is_a?(OSA::Finder::Item)
    puts "#{x.class.name.sub(/^.+::/, '').sub(/_/, ' ').ljust(25)} #{x.name}"
end


結果

RuntimeError: application returned error: Runtime resolution of an object failed. (-1728)

method __send_event__	in rbosa.rb at line 558
method name	in rbosa.rb at line 558
at top level	in show_desktop.rb at line 9
method each	in show_desktop.rb at line 7
at top level	in show_desktop.rb at line 7

Finder::Item にアクセスして item.name をとるところで 止まる...

p finder.desktop.methods を表示してなにが使えるか探してみたら...
items があったので

#ary = OSA.app('Finder').desktop.entire_contents.get
ary = OSA.app('Finder').desktop.items.get


に、したら動いた.

# =>
Disk          tiger
Disk          midori
Folder       rubyosa


items.get の .get がないと Disk も Folder も全てのアイテムは Itemクラス になってしまうのね。.get 要注意。
それにしても entire_contents は使われてないという意味なのだろうか?。

とりあえず理解を深めるためにもデスクトップをターゲットに頑張ってほりさげて...

デスクトップフォルダ以下全てのフォルダ名とファイル名の取得

# ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.9.1]
# rubyosa-0.4.0

require 'rbosa'
OSA.utf8_strings = true
finder = OSA.app('Finder')

def getfiles(obj)
  print "Folder::#{obj.url.gsub("file://localhost",'').scan(/\/Desktop.*/)}\n"
  obj.items.each{|i|
    case i.get.class.name
    when "OSA::Finder::DocumentFile"
      puts "File:: #{obj.name}/#{i.name}"
    end
  }
  my_index(obj.folders)
end

def my_index(obj)
  obj.each{|x|
  case x.get.class.name
  when "OSA::Finder::Disk": puts "Disk:: #{x.name}"
  when "OSA::Finder::Folder": getfiles(x)
  when "OSA::Finder::DocumentFile": puts "File:: #{x.name}"
  end
  }
end
my_index(finder.folders)


結果

Disk:: tiger
Disk:: hd
Folder::/Desktop/rbosa/
File:: rbosa/rbosa_test.rb
File:: rbosa/名称未設定.txt
Folder::/Desktop/rbosa/memo/
File:: memo/memo.rb
File:: memo/memo_in_ruby_2.zip
Folder::/Desktop/rbosa/memo/data/
File:: data/data.txt

なんとか再帰的にとれました。
#entire_contents を利用する方法はわからずじまい。
x.get.class.name っていうところはちょっとはまりました。やっぱり .get 要注意。

OSA::Finder::Folder クラスに属するオブジェクト

require 'rbosa'
OSA.utf8_strings = true
finder = OSA.app('Finder')

finder.desktop.folders.each{|i| p i.name}
puts "-----\n"

finder.desktop.folders.each{|i| p i.name if i.kind =~ /ボリューム/}
# i.kind => ボリューム or フォルダ

finder.desktop.folders.each{|i| p i.name if i.properties[:class].name =~ /Folder/ } 
# i.properties[:class].name => "OSA::Finder::Disk" or "OSA::Finder::Folder"

--telop
曇り

--imported_from
http://www.midore.net/daybook/2007/04/1176460414.html


+++ 追記 +++
2010-02-06

関連する記事
"RubyOSA"ラベルがついた全ての記事

2007/04/12

バッテリー

バッテリー残時間が一瞬556時間って出た。こわいよ。
--telop
曇り

--imported_from
http://www.midore.net/daybook/2007/04/1176369389.html

2007/03/29

Time at

Ruby で

Time.at(1)
=>Thu Jan 01 09:00:01 +0900 1970

1を指定すると 1970年の1月1日になった。
じゃ最大値はいくつまで許されているのだろうかと、試してみた。

t = Time.now
def checkepoc(num, max)
  while num <= max
    begin
    Time.at(num)
    num += 60
    rescue
     return num
    end
  end
end

num = 2140000000 #Bignum
max = 2150000000
p res = checkepoc(num, max)
#=>2147483648
puts Time.at(res-1)
#=>Tue Jan 19 12:14:07 +0900 2038
p Time.at(res)
#=> RangeError: bignum too big to convert into ‘long’


error がきたらループから抜けてその時の数字を返し1 秒だけ引いて日付を表示。最後にその数値で本当にエラーなるかだめ押しで確認。

限界値は 2147483648 。Time.at で日付に直すと 2038-01-19 12:14:07(日本時間)。
とっても中途半端な日付時刻なのね。?

--telop
晴れ

--imported_from
http://www.midore.net/daybook/2007/03/1175168999.html

+++ 追記 +++

2010-02-06
およそ3年ぶりに上記を実行してみたところ...

nil
(...) undefined method `-' for nil:NilClass (NoMethodError)

になってしまった。

ruby 1.9.1p376, ruby 1.8.7 どちらでも同様の結果だった。

まさかのもしや?

% ruby -v -rtime -e "t = Time.local(2040,01); n = t.to_i; p Time.at(n)"
ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]
Sun Jan 01 00:00:00 +0900 2040

% ruby19 -v -rtime -e "t = Time.local(2040,01); n = t.to_i; p Time.at(n)"
ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-darwin10.2.0]
2040-01-01 00:00:00 +0900


びっくり!。いつのまにか 2038 年問題は消えておりました。とさ。
ここにおいては。

% uname -sv
Darwin Darwin Kernel Version 10.2.0: Tue Nov  3 10:37:10 PST 2009; root:xnu-1486.2.11~1/RELEASE_I386


ついでに

 18 p n = Time.local(2038, 1, 1).to_i
 19 # => 2145884400
 20 p n.class
 21 # => Fixnum
 22 
 23 p n2 = n + 60*60*24
 24 # => 2145970800
 25 p n2.class
 26 # => Fixnum
 27 
 28 p Time.local(2041, 01, 01)
 29 # => 2041-01-01 00:00:00 +0900

2007/03/16

Ruby v1.8.6 and OS X 10.4.9

Mac OS X 10.4.9 にアップデートした。その後 Ruby 1.8.6 をインストールしてみた。configure オプション指定方法(Tiger)は下記を参考にした。

http://hivelogic.com/narrative/articles/ruby-rails-mongrel-mysql-osx
make test は成功だったのでインストールした。

標準ライブラリのディレクトリに
/usr/local/lib/ruby/1.8/i686-darwin8.9.1
/usr/local/lib/ruby/1.8/i686-darwin8.8.1
があり、i686-darwin8.8.1は ruby 1.8.5のライブラリ(ロードされていない)で
i686-darwin8.9.1の方には今回インストールされたライブラリがあるということのようだ。
/usr/local/lib/ruby/site_ruby/1.8/ にも同様にインストールされていた。

%ruby -v
ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.9.1]
% uname -prsv
Darwin 8.9.1 Darwin Kernel Version 8.9.1: Thu Feb 22 20:55:00 PST 2007; root:xnu-792.18.15~1/RELEASE_I386 i386

irbを動かしてみた。

irb(main):001:0> require 'date'
=> true
irb(main):002:0> require 'time'
=> true
irb(main):003:0> require 'find'
=> true
irb(main):004:0> require 'nkf'
=> false


なぜか、nkf がないと言われてしまった。nkf はnkfという名前じゃなくなったとかそういうこと?違うよな。例えば簡単ななにかを動かしてみると問題なく動いているようにみえるのが不思議。

require 'nkf'
str = '簡単ななにか'
s_str = NKF.nkf('-s', str)
p s_str
puts NKF.nkf('-w', str)
=>
"\212\310\222P\202\310\202\310\202\311\202\251"
簡単ななにか


ロードしているパスをみると
% ruby -e 'p $LOAD_PATH'
["/usr/local/lib/ruby/site_ruby/1.8", "/usr/local/lib/ruby/site_ruby/1.8/i686-darwin8.9.1", "/usr/local/lib/ruby/site_ruby", "/usr/local/lib/ruby/1.8", "/usr/local/lib/ruby/1.8/i686-darwin8.9.1", "."]

となっていて、nkf ライブラリもちゃんとあるみたい。

-rw-r--r--   1 root  wheel  343884 Mar 15 01:34 /usr/local/lib/ruby/1.8/i686-darwin8.9.1/nkf.bundle

nkf ライブラリというのは nkf.bundle 1つでそれが全てなのかどうかは調べてみないとわからない。。どいうことなんだろう。

次にRubyOSA0.3.0 を インストール。 gem は使ってない。
インストール方法はREADMEの通り。下記のディレクトリにインストールされた。

/usr/local/lib/ruby/site_ruby/1.8/rbosa.rb
/usr/local/lib/ruby/site_ruby/1.8/rbosa_properties.rb
/usr/local/lib/ruby/site_ruby/1.8/i686-darwin8.9.1/osa.bundle

begin require 'rubygems'; rescue LoadError; end
require 'rbosa'
finder =  OSA.app('Finder')
p finder.finder_windows.size
exit
=>1

ちゃんと動いた!。よかった
でも RubyOSA0.1の頃のものはちょっと書き直す必要ありそう。

--imported_from
http://www.midore.net/daybook/2007/03/1174019673.html


+++ 追記 +++
2010-02-06

関連する記事
"RubyOSA"ラベルがついた全ての記事

2007/03/15

rubyosa-0.3.0

rubyosa 0.3.0が公開されていた。(2007-03-03付け)
付属していたサンプルに「get_selected_mail.rb」というのがあったので試してみた。
Mail.app の受信メールメッセージを選択している時にこのスクリプトを動かすとテキストエディットが起動し選択していたメール本文内容がテキストエディットの本文に表示されるものだった。問題なく動いた。が、若干問題があった。
試したサンプル「get_selected_mail.rb」の中身。

%cat get_selected_mail.rb

# Retrieve and show every selected message content in Mail into new TextEdit documents. 

begin require 'rubygems'; rescue LoadError; end
require 'rbosa'

OSA.utf8_strings = true
textedit = OSA.app('TextEdit')
mailApp = OSA.app('Mail')
viewers = mailApp.message_viewers
viewers.each do |viewer|
  viewer.selected_messages.each do |message|
    textedit.make(OSA::TextEdit::Document).text = message.content
  end
end


英語の場合は全く問題ないけれど日本語で書かれたメール(Content-Type: text/plain; charset="ISO-2022-JP")の時は文字化けする。
OSA.utf8_strings = true となっているが効力を発揮していないようだ。発揮しているけれど途中経過で打ち消されているのかもしれない。

仕方ないので下記のように書き換えてみたところ文字化けが解消された。一旦 Shift-jis にしてからTextEditorに渡すようにしてみた。TextEditor 側の環境設定はデフォルト状態でも大丈夫だしUTF-8で「開く」「保存」となっていても問題なかった。
※ utf-8 で保存しておきたい場合は環境設定を変更しておくなり、テキスト保存時にutf-8を選択する必要がある。文字によってはここで保存できない場合もあるのかもしれない。

これをAppleScriptから呼び出すようにしAppleScript側でtry-on error -end にしてエラー処理を行うようにしたので Ruby側ではbegin...endをしていない。
また、サンプルにはない機能だが表示するテキストに引用府をつけ受信時刻と受信日付送信者の情報を付け足してみた。

#  j_get_selected_mail.rb
#  encoding: utf-8
#  ruby 1.8.5 

begin require 'rubygems'; rescue LoadError; end
require 'rbosa'

require 'nkf'
require 'time'
OSA.utf8_strings = true
textedit = OSA.app('TextEdit')
mailApp = OSA.app('Mail')
viewers = mailApp.message_viewers
viewers.each do |viewer|
  viewer.selected_messages.each do |message|
    # case rubyosa v2.0
    #mesdate = message.properties['alhe'].scan(/Date.*?\n/).to_s.gsub(/Date:\s/,'').chomp
    # rubyosa v3.0
    mesdate = Time.parse(message.source.scan(/Date.*?\n/).to_s.gsub(/Date:\s/,'').chomp)#
    mes_time = mesdate.strftime("%X")
    mes_date = mesdate.strftime("%y-%m-%d")
    # Message Body
    mes_body = NKF.nkf("-s", message.content)
    # Message Sender
    mes_sender = NKF.nkf("-s", message.sender)
    # Message Body
    res_str = "On #{mes_date}, at #{mes_time}, #{mes_sender} wrote:\n\n" + ">"  + mes_body.gsub("\n", "\n>")
    # Mail Contents send 'TextEdit.App'
    textedit.make(OSA::TextEdit::Document).text = res_str
  end
end


アップルスクリプト 側

 --j_get_selected_mail.scpt
 --2007-03-05
 --AppleScript's version "1.10.7"
 --RubyOSA ver 0.3.0[2007-03-03]
 --Mail.app バージョン 2.1.1(752.3)

try
  set myrubypath to "/usr/local/bin/ruby"
  set mypath to "/Users/midori/rubyosa3/j_get_selected_mail.rb"
  
  tell application "Mail"
    activate
  end tell
  
  set response to do shell script myrubypath & "  " & mypath
  if ("error") is in (response as Unicode text) then
    display dialog "Please select message(s) of Mail.app " buttons {"OK"} default button 1
    tell application "Mail"
      activate
    end tell
    return
  else
    tell application "TextEdit"
      activate
    end tell
    return
  end if
on error
  tell application "Finder"
    activate
    display dialog "error: Please select message(s) of Mail.app.
    or your ruby path exist?
    or your mypath  exist?
    or your Applescript's Version is old?
    or your RubyOSA is old? 
    or  something error... 
    " buttons {"OK"} default button 1
    return
  end tell
end try


--telop
曇時々雨

--imported_from
http://www.midore.net/daybook/2007/03/1173944973.html

+++ 追記 +++
2010-02-06

関連する記事
"RubyOSA"ラベルがついた全ての記事