どうせなら

すいません。更新できていませんね。

さて、最近は RSS リーダーに livedoor Reader を利用しています。Safari もいいのですが、未読数が表示されてしまうとなんとなく精神的によろしくなくて...。

livedoor Reader は、ブラウザで操作するいわゆる Web アプリケーションです。未読の件数を表示する Dashboard のウィジェットも配布されていたりして、Mac OS のことも考慮に入れられておりなかなかいい感じです。

で、今まではこのウィジェットを使って未読を確認し、ウィジェットから livedoor Reader のログインページに移動したりしていたのですが、どうせなら、ログインもついでに行ってくれるといいなと思ったのです。

こういうときこそ AppleScript。未読数を表示、(そのままログインしたいなら)livedoor Reader のページに移動し、ログインを行うスクリプトを作ってみました。

Script Editor で開く

property readerURL : "http://reader.livedoor.com/reader/"
property notifyAPI : "http://rpc.reader.livedoor.com/notify?user="
property livedoorID : "your livedoor ID is here."
property livedoorPassword : "your livedoor login password is here."

on run
    set itemNum to my unreadedCount()

    try
        tell application (path to frontmost application as Unicode text)
            display dialog "Unreaded Items : " & itemNum with icon 1 buttons {"Cancel", "Login"} default button 2
            my login()
        end tell
    on error
        return
    end try
end run

on unreadedCount()
    set theResult to do shell script "curl " & (notifyAPI & livedoorID)
    set the AppleScript's text item delimiters to "|"
    set theResult to every text item of theResult
    set the AppleScript's text item delimiters to {""}
    return (item 2 of theResult)
end unreadedCount

on login()
    tell application "Safari"
        activate
        make new document with properties {URL:readerURL}
        set bool to my pageLoaded(10)
        if bool then
            do JavaScript ("document.forms[0].livedoor_id.value = \"" & livedoorID & "\"") in document 1
            do JavaScript ("document.forms[0].password.value = \"" & livedoorPassword & "\"") in document 1
            do JavaScript "document.forms[0].submit()" in document 1
        else
            display dialog "Connection failure." with icon 0 buttons {"OK"} default button 1
        end if
    end tell
end login

on pageLoaded(timeoutValue)
    set num to (time of (current date)) + timeoutValue
    delay 1
    repeat
        tell application "Safari"
            if (do JavaScript "document.readyState" in document 1) is "complete" then
                return true
            end if
        end tell
        if (time of (current date)) is greater than num then exit repeat
    end repeat
    return false
end pageLoaded

プロパティの livedoorID と livedoorPassword を書き換えてご利用ください。JavaScript と curl を使えば、たいていのことはなんでもできちゃいそうな気がしないでもないです。

ちなみに、livedoor Reader では RSS を登録している人の数が表示されるのですが、「ちゃらんぽらん」は 8 人でした(多分)。登録している方々、毎度ごひいきにしていただきありがとうございます。

0 件のコメント :

コメントを投稿