从Ruby或PHP或可可访问Mac应用程序 [英] Accessing Mac applications from Ruby or PHP or Cocoa

查看:157
本文介绍了从Ruby或PHP或可可访问Mac应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想访问了几个从preferably红宝石不同的Mac OS X应用程序,但我会满足于PHP。这些应用程序Elgato的turbo.264和苹果公司的iTunes。两者都有AppleScript的图书馆定义,让我做什么我想从AppleScript的做的,但我不希望这样做的AppleScript的。如果我不能做到这一点在Ruby或PHP,也许我可以做在客观C /可可和创建某种包装的,我可以在Ruby中调用。

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.

这甚至可能吗?好像如果方法的AppleScript可他们应该在其他语言版本,我刚才没能发现任何东西。

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 ),然后你可以这样做:

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}"

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

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

这篇关于从Ruby或PHP或可可访问Mac应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆