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"ラベルがついた全ての記事