<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>blog.8-p.info: RubyCocoa で Skype に iTunes で再生してる曲を表示</title>
  <meta name="generator" content="Mephisto" />
  <link href="/stylesheets/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
  <div id="header">
    <h1>
      <a href="/2007/"><img src="/images/title.png" alt="blog.8-p.info"/></a>
    </h1>

    <div class="misc">
      <!-- Google CSE Search Box -->
    </div>
  </div>

  
  <div id="content" class="autopagerize_page_element">

<div class="entry entry-134463880">
  <h2 class="entry-title"><a href="/articles/2006/12/24/rubycocoa-skype-itunes" title="RubyCocoa で Skype に iTunes で再生してる曲を表示">RubyCocoa で Skype に iTunes で再生してる曲を表示</a></h2>
  <div class="published">
    December 24th, 2006
  </div>
  <div class="entry-content">
    
    <p><a href="http://blog.8-p.info/articles/2006/12/17/mac-skype-itunes">AppleScript で書いたやつ</a>の続き。RubyCocoa から Skype.framework と NSDistributedNotificationCenter を使っている。apple-unstable の RubyCocoa で動きます。</p>

<p>書いたのはちょっと前で、実行すると</p>

<pre><code>% ruby a.rb
/Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/objc/oc_wrapper.rb:17: [BUG] Bus Error
ruby 1.8.5 (2006-08-25) [powerpc-darwin8.8.0]

zsh: abort      ruby a.rb
</code></pre>

<p>と、なぜか落ちるので放置していたのだけど、<a href="http://fobj.com/hisa/d/20061222.html#p02">ひ日誌(2006-12-22)</a> で読んだ addRubyMethod_withType を足してみたら落ちなくなった。</p>
    
    
    
    <pre><code>require 'osx/cocoa'
OSX.require_framework 'Skype'

class Server &lt; OSX::NSObject
  def onPlayerInfo(n)
    s = "#{n.userInfo['Name']} / #{n.userInfo['Artist']}"
    OSX::SkypeAPI.sendSkypeCommand("SET PROFILE MOOD_TEXT #{s}")
  end

  def clientApplicationName
    'NowPlayingOnSkype'
  end

  addRubyMethod_withType 'skypeAttachResponse:', 'v@:i'
  def skypeAttachResponse(status)
    return if status != 1

    center = OSX::NSDistributedNotificationCenter.defaultCenter
    center.addObserver_selector_name_object_(self,
                                             'onPlayerInfo:',
                                             'com.apple.iTunes.playerInfo',
                                             'com.apple.iTunes.player')
  end
end


server = Server.alloc.init

OSX::SkypeAPI.setSkypeDelegate(server)
OSX::SkypeAPI.connect

OSX::NSRunLoop.currentRunLoop.run
</code></pre>
    
  </div>

  <div class="entrymeta">
    <ul>
      
      <li><a href="/tags/mac" rel="tag" title="mac">mac</a></li>
      
      <li><a href="/tags/ruby" rel="tag" title="ruby">ruby</a></li>
      
      <li><a href="/tags/skype" rel="tag" title="skype">skype</a></li>
      
    </ul>

    
  </div>
</div>


  <div class="commentsblock">
    




<!--
<h3 id="respond">Leave a Reply</h3>
<form id="comment-form" method="post" action="/articles/2006/12/24/rubycocoa-skype-itunes/comments#comment-form">
  <p><input type="text" id="comment_author" name="comment[author]" value="" /><label for="author"><small>Name (required)</small></label></p>
  <p><input type="text" id="comment_author_email" name="comment[author_email]" value="" /><label for="email"><small>Mail (will not be published)</small></label></p>
  <p><input type="text" id="comment_author_url" name="comment[author_url]" value="" /><label for="url"><small>Website</small></label></p>
  <p><textarea name="comment[body]" id="comment" cols="100%" rows="10"></textarea></p>
  <p><input name="submit" type="submit" id="submit" value="Submit Comment" /></p>
</form>
-->



  </div>

</div>







  <div id="footer">
    <p>
      All articles are written by <a href="http://8-p.info/">KATO Kazuyoshi</a>.
    </p>
  </div>

</body>
</html>
