2006/11/11

RubyOSA Safari を試す

いま開いている Safari のロケーションから
body 要素を取り出しソースとテキストを表示してみました。

require 'rbosa'
require 'nkf'
app = OSA.app('Safari')

if app.documents.size > 0
  # Get HTML Source
  source = app.documents[0].source
  # Get Body
  body = source.split('<body>')[1].split('</body>')[0]
  puts '------ html source \n'
  puts NKF.nkf('-w -Lu', body)
  puts '------ text \n'
  # HTML タグの除去 - >かなりな大雑把版。それに Source が UTF8だと決めつけてます。
  print NKF.nkf('-w -Lu', body.gsub(/\<.*?\>|<\/|>|<script.*?\>/m, ''))
else
 # 空白ページが開かれていたら終わる.これ以外のエラーには未対処。
  puts 'no doc'
end


--imported_from
http://www.midore.net/daybook/2006/11/1163227004.html

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

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

2006/11/08

RubyOSA 0.1 のFinderを試す

# Finder をアクティブにする

tell the application 'Finder' to activate

は、RubyOSA だと

OSA.app('Finder').activate

#home 以下全フォルダ名の取得 --get all folder's name of path to home

tell the application 'Finder'
  return name of folders of home
end tell

は、RubyOSA だと

OSA.app('Finder').home.folders.to_a.each{ |folder| puts folder.name }

#Desktop 上の全ファイル名の取得

tell the application 'Finder' to name of every document file in the desktop

は、RubyOSA だと

require 'nkf'
OSA.app('Finder').document_files.each{ |file| puts NKF.nkf('-w -Lu', file.name)}

end

--imported_from
http://www.midore.net/daybook/2006/11/1162972588.html


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

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

2006/11/02

iTunes ライブラリの曲

rubyosa を使って iTunes ライブラリの曲(全曲)を次から次へと再生する試み。
sleep 3で3秒を指定しています。

require 'rbosa'
require 'nkf'
itunes = OSA.app('iTunes')
itunes_libray = itunes.sources[0].playlists[0]
#=> ['ライブラリ']
itunes_libray.play

until itunes.current_track.name.nil?
  puts NKF.nkf('-w -Lu', itunes.current_track.name ) #current_track.name.toutf8
  sleep 3
  itunes.next_track
end


itunes_libray = itunes.sources[0].playlists[0] ここの数字を変えるとライブラリじゃなくて自分で作成したプレイリストを指定できた。
でも自分で作ったプレイリストを指定したいときはダイアログから名前を指定できるといいのかなと、OSA.app('Finder').display dialogの命令を探してみたんですがわからなかった。。。

--imported_from
http://www.midore.net/daybook/2006/11/1162440770.html

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

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