Created
April 6, 2013 01:19
-
-
Save sakuna63/5324237 to your computer and use it in GitHub Desktop.
以下のサイトのスクリプトを改変して作ったNetNewsWireで見ている記事をPocketに送るスクリプト。
http://jaidev.info/hacks/NetNewsWire+Pocket 使用するにはNotification Scriptingというアプリを入れる必要があります。(通知センター難しすぎぃ)
Notification Scriptingの実装は以下を参考にしました。
http://veadardiary.blog29.fc2.com/blog-entry-4110.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- NetNewsWire+Pocket: Add items to Pocket (Read It Later) from NetNewsWire. | |
-- Copyright (c) 2005-2011, Jaidev K Sridhar <mail . jaidev @ info> | |
-- Released under the GPL license version 2. http://www.gnu.org/licenses/gpl-2.0.html | |
-- INSTALLING: | |
-- Copy NetNewsWire+Pocket.scpt to /Users/$USER/Library/Application\ Support/NetNewsWire/Scripts/. A new item 'NetNewsWire+Pocket' shows up in the scripts menu when NetNewsWire is restarted. | |
-- ADDING A KEYBOARD SHORTCUT: | |
-- To configure a keyboard shortcut, open System Preferences > Keyboard > Keyboard Shortcuts > Application Shortcuts. Add a keyboard shortcut with these parameters: | |
-- * Application: NetNewsWire | |
-- * Menu Title: NetNewsWire+Pocket | |
-- * Keyboard Shortcut: Any key combination. (I use CMD + D). | |
tell application "NetNewsWire" | |
if index of selected tab = 0 then | |
-- We're looking at headlines, so just get the headline URL | |
set feed_url to URL of selectedHeadline | |
set feed_title to title of selectedHeadline | |
else | |
-- We're looking at a web view tab, so we need to know which tab | |
set i to index of selected tab | |
set i to i + 1 | |
-- Get the tab's URL | |
set URL_list to URLs of tabs | |
set title_list to titles of tabs | |
set feed_url to item i of URL_list | |
set feed_title to item i of title_list | |
end if | |
set pocket_user to do shell script "security 2> /dev/null find-internet-password -gs getpocket.com | grep acct | cut -d '\"' -f4" | |
if pocket_user = "" then | |
display dialog "Pocket (Read it Later) username: " with title "NetNewsWire+Pocket" default answer "" buttons {"OK"} default button 1 | |
set pocket_user to (text returned of result) | |
display dialog "Enter password for " & pocket_user & " on Pocket: " with title "NetNewsWire+Pocket" default answer "" buttons {"OK"} default button 1 with hidden answer | |
set pocket_pass to (text returned of result) | |
set qpass to do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & quoted form of pocket_pass | |
set auth_url to "https://readitlaterlist.com/v2/auth?username=" & pocket_user & "&password=" & qpass & "&apikey=e7dd1Ne1TfY49E1d78A573ete5g5k2c2" | |
set cmd to "curl '" & auth_url & "'" | |
set ret to do shell script (cmd) | |
if "200 OK" is in ret then | |
set cmd to "security add-internet-password -D 'Web form password' -r 'http' -a " & pocket_user & " -s getpocket.com -w " & pocket_pass & " -l 'getpocket.com (" & pocket_user & ")' -j default" | |
do shell script cmd | |
else | |
display dialog "Failed to authenticate user '" & pocket_user & "' on getpocket.com (" & ret & "). Please retry." with title "NetNewsWire+Pocket" buttons {"OK"} | |
return | |
end if | |
else | |
set pocket_pass to do shell script "security find-internet-password -s getpocket.com -g 2>&1 >/dev/null | cut -d '\"' -f2" | |
end if | |
set qurl to do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & quoted form of feed_url | |
set qtitle to do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & quoted form of feed_title | |
set qpass to do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & quoted form of pocket_pass | |
set pocket_url to "https://readitlaterlist.com/v2/add?username=" & pocket_user & "&password=" & qpass & "&apikey=e7dd1Ne1TfY49E1d78A573ete5g5k2c2&url=" & qurl & "&title=" & qtitle | |
set cmd to "curl '" & pocket_url & "'" | |
set ret to do shell script (cmd) | |
if "200 OK" is in ret then | |
tell application "AppleScript Editor" | |
set «class NUsp» to (path to me) | |
set dict to {theName:"Notifications Scripting", theVersion:"1.0", theScript:«class NUsp»} | |
«event NUdisnot» "Success" given «class NUst»:"Add to Pocket", «class NUit»:feed_title & " (" & feed_url & ")", «class NUsd»:"Default", «class NUus»:dict | |
quit | |
end tell | |
else | |
tell application "AppleScript Editor" | |
set «class NUsp» to (path to me) | |
set dict to {theName:"Notifications Scripting", theVersion:"1.0", theScript:«class NUsp»} | |
«event NUdisnot» "Error" given «class NUst»:"Can't Add to Pocket", «class NUit»:feed_title & " (" & feed_url & ")", «class NUsd»:"Default", «class NUus»:dict | |
quit | |
end tell | |
end if | |
end tell | |
using terms from application "AppleScript Editor" | |
on «event NUdidlvd» given «class NUtt»:aTitle, «class NUst»:aSubTitle, «class NUit»:aMessage, «class NUdd»:aDeliveryDate, «class NUus»:aDict | |
end «event NUdidlvd» | |
on «event NUdiactv» given «class NUtt»:aTitle, «class NUst»:aSubTitle, «class NUit»:aMessage, «class NUdd»:aDeliveryDate, «class NUat»:aType, «class NUus»:aDict | |
end «event NUdiactv» | |
end using terms from |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment