从Ruby或PHP或Cocoa访问Mac应用程序(Accessing Mac applications from Ruby or PHP or Cocoa)

编程入门 行业动态 更新时间:2024-10-23 22:30:09
从Ruby或PHP或Cocoa访问Mac应用程序(Accessing Mac applications from Ruby or PHP or Cocoa)

我想从Ruby中访问几个不同的Mac OS X应用程序,但是我会选择PHP。 这些应用程序是Elgato的turbo.264和Apple的iTunes。 两个都定义了Applescript Libraries,它可以让我做我想从Applescript做的事情,但我不想在Applescript中做到这一点。 如果我不能在Ruby或PHP中做到这一点,也许我可以在目标C / Cocoa中做到这一点,并创建一些我可以从Ruby调用的包装器。

这甚至有可能吗? 似乎如果这些方法在Applescript中可用,它们应该以其他语言提供,我只是无法找到任何东西。

I would like to access a couple of different Mac OS X applications from preferably Ruby, but I would settle for PHP. The applications are Elgato's turbo.264 and Apple's iTunes. Both have Applescript Libraries defined that would allow me to do what I want to do from Applescript, but I don't want to do this in Applescript. If I can't do this in Ruby or PHP, perhaps I can do it in objective C / Cocoa and create some kind of wrapper that I could call from Ruby.

Is this even possible? It seems like if the methods are available in Applescript they should be available in other languages, I have just not been able to find anything.

最满意答案

尝试RubyOSA( http://rubyosa.rubyforge.org ),然后你可以这样做:

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's status message to the current track. OSA.app('iChat').status_message = "Playing: #{track.name}"

您可以与任何支持AppleScript的Mac OS X应用程序交谈

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's status message to the current track. OSA.app('iChat').status_message = "Playing: #{track.name}"

You can talk to any Mac OS X app that supports AppleScript

更多推荐

本文发布于:2023-07-23 18:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1235595.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   Cocoa   Ruby   PHP   applications

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!