Merge pull request #3 from brentsimmons/mac-candidate

merge from brentsimmons/mac-candidate
This commit is contained in:
Olof Hellman 2019-07-17 19:51:05 -07:00 committed by GitHub
commit 4d62925bc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 113 additions and 9 deletions

View File

@ -0,0 +1,49 @@
-- This script creates an Excel spreadsheet with statistics about all the feeds in your NetNewsWire
-- the exportToExcel() function creats a single line of data in a spreadsheet
to exportToExcel(docname, rowIndex, feedname, numArticles, numStars, numRead)
tell application "Microsoft Excel"
tell worksheet 1 of document docname
set value of cell 1 of row rowIndex to feedname
set value of cell 2 of row rowIndex to numArticles
set value of cell 3 of row rowIndex to numStars
set value of cell 4 of row rowIndex to numRead
end tell
end tell
end exportToExcel
-- the script starts here
-- First, we make a new Excel spreadsheet and fill in the column headers
tell application "Microsoft Excel"
set newdoc to make new document
tell worksheet 1 of newdoc
set value of cell 1 of row 1 to "Name of Feed"
set value of cell 2 of row 1 to "Articles"
set value of cell 3 of row 1 to "Read"
set value of cell 4 of row 1 to "Stars"
end tell
set docname to name of newdoc
end tell
-- Then we loop though all the feeds of all the accounts
-- for each feed, we calculate how many articles there are, how many are read, and how many are starred
-- then, we send off the information to Excel
set totalFeeds to 0
tell application "NetNewsWire"
set allAccounts to every account
repeat with nthAccount in allAccounts
set allFeeds to every feed of nthAccount
repeat with nthFeed in allFeeds
set feedname to name of nthFeed
set articleCount to count (get every article of nthFeed)
set readCount to count (get every article of nthFeed where read is true)
set starCount to count (get every article of nthFeed where starred is true)
set totalFeeds to totalFeeds + 1
my exportToExcel(docname, totalFeeds + 1, feedname, articleCount, readCount, starCount)
end repeat
end repeat
end tell

View File

@ -0,0 +1,42 @@
-- This script presumes that you are an OmniFocus user,
-- and that you'd like to have a project in OmniFocus for a reading list of articles from NetNewsWire.
-- Running this script creates a new task in an OmniFocus project called "NetNewsWire reading list"
-- with information about the current article.
-- Ideally, the name of the task will be the name of the article, but some articles don't have names
-- so if there is not name for the article, just use a default string "A NetNewsWireArticle without a title"
to getTitleOrSomething()
tell application "NetNewsWire"
set myTitle to the title of the current article
if (myTitle is "") then
set myTitle to "A NetNewsWireArticle without a title"
end if
end tell
end getTitleOrSomething
-- Here's where the script starts
-- first get the url and the title of the current article
tell application "NetNewsWire"
set myUrl to the url of the current article
set myTitle to my getTitleOrSomething()
end tell
tell application "OmniFocus"
tell document 1
-- Second, ensure that the front OmniFocus document has a project called "NetNewsWire reading list"
set names to name of every project
if names does not contain "NetNewsWire reading list" then
make new project with properties {name:"NetNewsWire reading list"}
end if
-- lastly, add a task in that project referring to the current article
-- the "Note" field of the task will contain the url for the article
tell project "NetNewsWire reading list"
make new task with properties {name:myTitle, note:myUrl}
end tell
end tell
end tell

2
AppleScript/README.md Normal file
View File

@ -0,0 +1,2 @@
Sample AppleScript scripts go in this folder.

View File

@ -401,7 +401,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
return feed return feed
} }
public func removeFeed(_ feed: Feed, from container: Container?, completion: @escaping (Result<Void, Error>) -> Void) { public func removeFeed(_ feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
delegate.removeFeed(for: self, with: feed, from: container, completion: completion) delegate.removeFeed(for: self, with: feed, from: container, completion: completion)
} }

View File

@ -36,7 +36,7 @@ protocol AccountDelegate {
func createFeed(for account: Account, url: String, name: String?, container: Container, completion: @escaping (Result<Feed, Error>) -> Void) func createFeed(for account: Account, url: String, name: String?, container: Container, completion: @escaping (Result<Feed, Error>) -> Void)
func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result<Void, Error>) -> Void) func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result<Void, Error>) -> Void)
func addFeed(for account: Account, with: Feed, to container: Container, completion: @escaping (Result<Void, Error>) -> Void) func addFeed(for account: Account, with: Feed, to container: Container, completion: @escaping (Result<Void, Error>) -> Void)
func removeFeed(for account: Account, with feed: Feed, from container: Container?, completion: @escaping (Result<Void, Error>) -> Void) func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void)
func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result<Void, Error>) -> Void) func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result<Void, Error>) -> Void)
func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> Void) func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> Void)

View File

@ -392,7 +392,7 @@ final class FeedbinAccountDelegate: AccountDelegate {
} }
func removeFeed(for account: Account, with feed: Feed, from container: Container?, completion: @escaping (Result<Void, Error>) -> Void) { func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
if feed.folderRelationship?.count ?? 0 > 1 { if feed.folderRelationship?.count ?? 0 > 1 {
deleteTagging(for: account, with: feed, from: container, completion: completion) deleteTagging(for: account, with: feed, from: container, completion: completion)
} else { } else {

View File

@ -139,8 +139,8 @@ final class LocalAccountDelegate: AccountDelegate {
completion(.success(())) completion(.success(()))
} }
func removeFeed(for account: Account, with feed: Feed, from container: Container?, completion: @escaping (Result<Void, Error>) -> Void) { func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
container?.removeFeed(feed) container.removeFeed(feed)
completion(.success(())) completion(.success(()))
} }

View File

@ -1,4 +1,4 @@
{\rtf1\ansi\ansicpg1252\cocoartf1671\cocoasubrtf200 {\rtf1\ansi\ansicpg1252\cocoartf1671\cocoasubrtf500
{\fonttbl\f0\fnil\fcharset0 LucidaGrande-Bold;\f1\fnil\fcharset0 LucidaGrande;} {\fonttbl\f0\fnil\fcharset0 LucidaGrande-Bold;\f1\fnil\fcharset0 LucidaGrande;}
{\colortbl;\red255\green255\blue255;\red0\green0\blue0;} {\colortbl;\red255\green255\blue255;\red0\green0\blue0;}
{\*\expandedcolortbl;;\cssrgb\c0\c0\c0\cname textColor;} {\*\expandedcolortbl;;\cssrgb\c0\c0\c0\cname textColor;}
@ -32,7 +32,7 @@ Major code contributors: {\field{\*\fldinst{HYPERLINK "https://github.com/olofhe
\f0\b \cf2 Thanks:\ \f0\b \cf2 Thanks:\
\pard\pardeftab720\li360\sa60\partightenfactor0 \pard\pardeftab720\li360\sa60\partightenfactor0
\f1\b0 \cf2 Thanks to Sheila and my family; thanks to my friends in Seattle and around the globe; thanks to my co-workers and friends at {\field{\*\fldinst{HYPERLINK "https://www.omnigroup.com/"}}{\fldrslt The Omni Group}}; thanks to the ever-patient and ever-awesome NetNewsWire beta testers.\ \f1\b0 \cf2 Thanks to Sheila and my family; thanks to my friends in Seattle and around the globe; thanks to my co-workers and friends at {\field{\*\fldinst{HYPERLINK "https://www.omnigroup.com/"}}{\fldrslt The Omni Group}}; thanks to the ever-patient and ever-awesome NetNewsWire beta testers. Thanks to {\field{\*\fldinst{HYPERLINK "https://github.com/"}}{\fldrslt GitHub}}, {\field{\*\fldinst{HYPERLINK "https://slack.com/"}}{\fldrslt Slack}}, and {\field{\*\fldinst{HYPERLINK "https://circleci.com/"}}{\fldrslt CircleCI}} for making open source collaboration easy and fun.\
\ \
\pard\pardeftab720\sa60\partightenfactor0 \pard\pardeftab720\sa60\partightenfactor0

View File

@ -58,8 +58,10 @@ class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjectConta
var container: Container? = nil var container: Container? = nil
if let scriptableFolder = scriptableFeed.container as? ScriptableFolder { if let scriptableFolder = scriptableFeed.container as? ScriptableFolder {
container = scriptableFolder.folder container = scriptableFolder.folder
} else {
container = account
} }
account.removeFeed(scriptableFeed.feed, from: container) { result in account.removeFeed(scriptableFeed.feed, from: container!) { result in
} }
} }
} }

View File

@ -153,19 +153,28 @@ private struct SidebarItemSpecifier {
func delete(completion: @escaping () -> Void) { func delete(completion: @escaping () -> Void) {
if let feed = feed { if let feed = feed {
guard let container = path.resolveContainer() else {
completion()
return
}
BatchUpdate.shared.start() BatchUpdate.shared.start()
account?.removeFeed(feed, from: path.resolveContainer()) { result in account?.removeFeed(feed, from: container) { result in
BatchUpdate.shared.end() BatchUpdate.shared.end()
completion() completion()
self.checkResult(result) self.checkResult(result)
} }
} else if let folder = folder { } else if let folder = folder {
BatchUpdate.shared.start() BatchUpdate.shared.start()
account?.removeFolder(folder) { result in account?.removeFolder(folder) { result in
BatchUpdate.shared.end() BatchUpdate.shared.end()
completion() completion()
self.checkResult(result) self.checkResult(result)
} }
} }
} }