2018-01-11 09:51:25 +01:00
|
|
|
//
|
|
|
|
// NSApplication+Scriptability.swift
|
|
|
|
// Evergreen
|
|
|
|
//
|
|
|
|
// Created by Olof Hellman on 1/8/18.
|
|
|
|
// Copyright © 2018 Olof Hellman. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2018-02-03 07:51:32 +01:00
|
|
|
import AppKit
|
2018-01-11 09:51:25 +01:00
|
|
|
import Account
|
2018-01-24 09:06:34 +01:00
|
|
|
import Data
|
2018-01-11 09:51:25 +01:00
|
|
|
|
|
|
|
extension NSApplication : ScriptingObjectContainer {
|
|
|
|
|
|
|
|
var scriptingClassDescription: NSScriptClassDescription {
|
|
|
|
return NSApplication.shared.classDescription as! NSScriptClassDescription
|
|
|
|
}
|
|
|
|
|
|
|
|
var scriptingKey: String {
|
|
|
|
return "application"
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc(accounts)
|
|
|
|
func accounts() -> NSArray {
|
|
|
|
let accounts = AccountManager.shared.accounts
|
|
|
|
return accounts.map { ScriptableAccount($0) } as NSArray
|
|
|
|
}
|
|
|
|
|
2018-01-24 09:06:34 +01:00
|
|
|
/*
|
|
|
|
accessing feeds from the application object skips the 'account' containment hierarchy
|
|
|
|
this allows a script like 'articles of feed "The Shape of Everything"' as a shorthand
|
|
|
|
for 'articles of feed "The Shape of Everything" of account "On My Mac"'
|
|
|
|
*/
|
|
|
|
@objc(feeds)
|
|
|
|
func feeds() -> NSArray {
|
|
|
|
let accounts = AccountManager.shared.accounts
|
|
|
|
let emptyFeeds:[Feed] = []
|
|
|
|
let feeds = accounts.reduce(emptyFeeds) { (result, nthAccount) -> [Feed] in
|
2018-01-28 03:50:48 +01:00
|
|
|
let accountFeeds = nthAccount.children.compactMap { $0 as? Feed }
|
2018-01-24 09:06:34 +01:00
|
|
|
return result + accountFeeds
|
|
|
|
}
|
|
|
|
return feeds.map { ScriptableFeed($0, container:self) } as NSArray
|
|
|
|
}
|
2018-01-11 09:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|