Try using Cocoa (macOS API) from Ruby. There used to be something called RubyCocoa. It seems to be stuck now. A close one is a gem package called cocoa. https://github.com/patrickhno/cocoa/
install.
% gem install cocoa Successfully installed cocoa-0.1.6 Parsing documentation for cocoa-0.1.6 Done installing documentation for cocoa after 3 seconds 1 gem installed
Try running the sample program.
test1.rb
require 'cocoa'
Cocoa::NSAutoreleasePool.new
app = Cocoa::NSApplication.sharedApplication
app.setActivationPolicy Cocoa::NSApplicationActivationPolicyRegular
app.activateIgnoringOtherApps true
alert = Cocoa::NSAlert.alloc.init.autorelease
alert.setMessageText "Hello world!"
alert.runModal
% ruby test1.rb /usr/local/lib/ruby/gems/2.7.0/gems/cocoa-0.1.6/lib/cocoa/objc/method_def.rb:154: warning: constant ::Fixnum is deprecated /usr/local/lib/ruby/gems/2.7.0/gems/cocoa-0.1.6/lib/cocoa/objc/method_def.rb:154: warning: constant ::Fixnum is deprecated /usr/local/lib/ruby/gems/2.7.0/gems/cocoa-0.1.6/lib/cocoa/objc/method_def.rb:154: warning: constant ::Bignum is deprecated
It runs safely, but don't worry about the warning. Let's fix it next time.
Recommended Posts