Access Mac Applications with Ruby or PHP or Cocoa

I would like to access several Ruby Mac OS X applications, but I would agree to PHP. Applications - Elgato turbo.264 and Apple iTunes. Both of them have Applescript library libraries that will allow me to do what I want to do from Applescript, but I do not want to do this in Applescript. If I cannot do this in Ruby or PHP, perhaps I can do this in a C / Cocoa object and create some kind of wrapper that I could call from Ruby.

Is it possible? It seems that if the methods are available in Applescript, they should be available in other languages, I just could not find anything.

+3
source share
3 answers

Try RubyOSA ( http://rubyosa.rubyforge.org ) and then you can do this:

require 'rbosa'
itunes = OSA.app('iTunes')

track = itunes.current_track
p track                     # <OSA::Itunes::FileTrack:0x1495e20>
p track.name                # "Over The Rainbow" 
p track.artist              # "Keith Jarrett" 
p track.duration            # 362.368988037109 
p track.date_added.to_s     # "2006-06-30" 
p track.enabled?            # true

# Play the selected track.
itunes.play                    

# Fade the volume.
100.times { |i| itunes.sound_volume = i; sleep 0.1 }  

# Set iChat status message to the current track.
OSA.app('iChat').status_message = "Playing: #{track.name}"

You can talk with any Mac OS X that supports AppleScript.

+4
source

Tried appscript ( http://appscript.sourceforge.net/rb-appscript/index.html )?

Example from the site:

Instead of AppleScript :

tell application "TextEdit"
    get paragraph 1 of document "ReadMe"
end tell

You write in Ruby:

app('TextEdit').documents['ReadMe'].paragraphs[1].get
+3
source

Mac OS X 10.5 ( ) Scripting Bridge, , AppleScript Cocoa, RubyCocoa PyObjC. , :

require 'osx/cocoa'
require_framework 'ScriptingBridge'
include OSX

iTunes = SBApplication.applicationWithBundleIdentifier 'com.apple.iTunes'
iTunes.activate
puts "Play #{iTunes.currentTrack.name}?"
iTunes.playpause if gets.strip == "Yes"
+3

Source: https://habr.com/ru/post/1715217/


All Articles