LoginSignup
1
1

More than 5 years have passed since last update.

MacRuby で OSX 10.8 の NSSharingService を使う

Posted at

NSSharingService を使用すると、簡単に Twitter にツイートを投稿できるようです。

MacRuby Nightly をインストール

Xcode 4.3.3 から Xcode の Framework のサーチパスが変わったらしく、MacRuby アプリケーションを作成しようとするとビルドエラーになります。
https://github.com/MacRuby/MacRuby/issues/107

そこで、最新の MacRuby Nightly インストールします。
https://macruby.macosforge.org/files/nightlies/

Xcode で NSSharingService を使用するアプリケーションを作成

MacRuby Applications というXcode のテンプレートを用いて、アプリケーションのプロジェクトを作成します。

その後、以下のようなコードを AppDelegate.rb に記述すると簡単な通知が行えます

AppDelegate.rb
class AppDelegate
  attr_accessor :window
  def applicationDidFinishLaunching(a_notification)
    # Insert code here to initialize your application
    serv = NSSharingService.sharingServiceNamed(NSSharingServiceNamePostOnTwitter)
    serv.performWithItems(["test tweet"])
  end
end

アプリケーションを実行すると、以下のようにメッセージが埋め込まれた状態でツイートするためのウィンドウがポップアップします。

Tweet

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1