如何使用AppleScript获取tweet



我想在AppleScript中获取最新的tweet。然而,"状态"变量不能保存。如何存储tweet状态对象?

It is working:

tell application "Twitter"
  set tw to text of item 1 of statuses of home timeline of current account
end tell

它不工作:

tell application "Twitter"
  set tw to item 1 of statuses of home timeline of current account
  set txt to text of tw
end tell

现在说这个有点晚了,但看看我的应用程序"Twitter Scripter"在Mac AppStore上是免费的。

这是一个无脸的后台应用程序,旨在使从AppleScript访问Twitter API变得微不足道。它支持OS X(10.8+)的原生Twitter支持,所以你不需要自己处理任何身份验证。你可以从twitter API中以结构化AppleScript记录的形式检索响应。

例如:

tell app "Twitter Scripter"
  set myTwitterAccount to item 1 of (available accounts) as string
  -- User timeline: This function retrieves the Tweets for a given user name
  fetch user timeline for username "mousedownsoft" using account myTwitterAccount with excluding replies and including retweets
end

Twitter有点奇怪。但是如果你只需要获得多个属性,你可以使用tell块或并行赋值。

tell application "Twitter"
    tell item 1 of statuses of home timeline of current account
        set t to text
        set u to url
        properties
    end tell
    -- set {t, u} to {text, url} of item 1 of statuses of home timeline of current account
end tell

或者你可以用API代替吗?如果你运行sudo gem install twitter并在dev.twitter.com注册一个应用程序,这应该可以工作。

require 'rubygems'
require 'twitter'
Twitter.configure { |config|
    config.consumer_key = ""
    config.consumer_secret = ""
    config.oauth_token = ""
    config.oauth_token_secret = ""
}
p Twitter.home_timeline.first.text
p Twitter.home_timeline.first.inspect

最新更新