« WebSocketRemoteのREADMEを英語で書いてみた | メイン | Re:長期間の使用で重くなったFirefoxを一瞬で軽くする方法(追記あり) »

AppleScriptでTwitterの検索結果を取得しKeynoteに表示するKeynotterというものを作ろうとして失敗した

まあ、ネタアプリなんだけど...。
AppleScriptだけで作れた面白いだろうなと勢いでコーディング開始。
Twitterからのデータの取得部分が問題になると思っていた。
だから、Twitterの公式検索機能からRSSを取得できるとわかった時点でメドがたったと勘違いしてしまった。
データの取得まではできたけど、Keynote上に指定した文字列を表示させる事ができなかった。
バージョンはKeynote'08(4.0)。
もしかしたら最新バージョンでは可能かもしれないけど...。
他の表示方法も探したんだけどうまい方法は見つからなかった。
とりあえず、コードを載せておくことにする。
出力はlog出力しているのでイベントログに表示される。
set tempUserName to "keynotter"
set tempFileName to "temp.xml"
set urlText to "http://search.twitter.com/search.atom"
set lastUpdated to "" as text
set lastTweet to "" as text
set lastUserName to "" as text
set answer to display dialog "See what's happening — right now." default answer "Kanasansoft" buttons {"cancel", "search and display"} default button 2 with icon note
if button returned of answer is "cancel" then
    return
end if
set query to "q=" & text returned of answer

tell application "Finder"
    set tempUser to path to temporary items folder from user domain
    if not (exists folder tempUserName of folder tempUser) then
        make new folder at folder tempUser with properties {name:tempUserName}
    end if
    set tempApp to folder tempUserName of tempUser
    set tempFilePath to (tempApp as text) & tempFileName
end tell
repeat
    tell application "URL Access Scripting"
        download urlText to file tempFilePath replacing yes form data query with progress
    end tell
    set tempFile to file tempFileName of tempApp as text
    tell application "System Events"
        set root to XML element "feed" of contents of XML file tempFile
        log (get properties of root) --prop
        set entries to ((XML elements of root) whose name is "entry") as list
        repeat with i from 1 to count of entries
            set entry to item i of entries
            set updated to (value of XML element "updated" of entry) as text
            set tweet to (value of XML element "title" of entry) as text
            set userName to (value of XML element "name" of XML element "author" of entry) as text
            if i is 1 then
                set firstUpdated to updated as text
                set firstTweet to tweet as text
                set firstUserName to userName as text
            end if
            if updated is lastUpdated and tweet is lastTweet and userName is lastUserName then
                set lastUpdated to firstUpdated as text
                set lastTweet to firstTweet as text
                set lastUserName to firstUserName as text
                exit repeat
            end if
            log tweet
            log userName
            if i is (count of entries) then
                set lastUpdated to firstUpdated as text
                set lastTweet to firstTweet as text
                set lastUserName to firstUserName as text
            end if
        end repeat
        delay 30
    end tell
end repeat

コメントを投稿

(いままで、ここでコメントしたことがないときは、コメントを表示する前にこのブログのオーナーの承認が必要になることがあります。承認されるまではコメントは表示されません。そのときはしばらく待ってください。)

Google

タグ クラウド