LoginSignup
2
2

More than 5 years have passed since last update.

MacRuby で OSX 10.8 の NSUserNotificationCenter を使う

Posted at

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 で通知を行うアプリケーションを作成

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

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

AppDelegate.rb
module Notification
  module_function
  def send(title, text)
    notification = NSUserNotification.alloc.init
    notification.title = title
    notification.informativeText = text

    center = NSUserNotificationCenter.defaultUserNotificationCenter
    center.scheduleNotification(notification)
  end
end

class AppDelegate
  attr_accessor :window

  def applicationDidFinishLaunching(a_notification)
    Notification.send("title", "text")
  end
end
2
2
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
2
2