diff --git a/Evergreen.xcodeproj/project.pbxproj b/Evergreen.xcodeproj/project.pbxproj index a922d870f..5c3c2504c 100644 --- a/Evergreen.xcodeproj/project.pbxproj +++ b/Evergreen.xcodeproj/project.pbxproj @@ -138,6 +138,9 @@ D5907D972004B7EB005947E5 /* Account+Scriptability.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5907D962004B7EB005947E5 /* Account+Scriptability.swift */; }; D5907DB22004BB37005947E5 /* ScriptingObjectContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5907DB12004BB37005947E5 /* ScriptingObjectContainer.swift */; }; D5907DB32005F45D005947E5 /* AppleEventUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5558FD7200228B80066386B /* AppleEventUtils.swift */; }; + D5A2678C20130ECF00A8D3C0 /* Author+Scriptability.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5A2678B20130ECF00A8D3C0 /* Author+Scriptability.swift */; }; + D5A2679C201312F900A8D3C0 /* testNameOfAuthors.applescript in Sources */ = {isa = PBXBuildFile; fileRef = D5A2679B201312F900A8D3C0 /* testNameOfAuthors.applescript */; }; + D5A2679D201313A200A8D3C0 /* testNameOfAuthors.applescript in CopyFiles */ = {isa = PBXBuildFile; fileRef = D5A2679B201312F900A8D3C0 /* testNameOfAuthors.applescript */; }; D5D1751220020B980047B29D /* Evergreen.sdef in Resources */ = {isa = PBXBuildFile; fileRef = D5D175012002039D0047B29D /* Evergreen.sdef */; }; D5F4EDB5200744A700B9E363 /* ScriptingObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5F4EDB4200744A700B9E363 /* ScriptingObject.swift */; }; D5F4EDB720074D6500B9E363 /* Feed+Scriptability.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5F4EDB620074D6500B9E363 /* Feed+Scriptability.swift */; }; @@ -439,6 +442,7 @@ dstPath = TestScripts; dstSubfolderSpec = 7; files = ( + D5A2679D201313A200A8D3C0 /* testNameOfAuthors.applescript in CopyFiles */, D5F4EDE920075C6700B9E363 /* testNameAndUrlOfEveryFeed.applescript in CopyFiles */, D5F4EDEA20075C6700B9E363 /* testNameOfEveryFolder.applescript in CopyFiles */, D5907CA2200232AD005947E5 /* testGenericScript.applescript in CopyFiles */, @@ -578,6 +582,8 @@ D5907D7E2004AC00005947E5 /* NSApplication+Scriptability.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSApplication+Scriptability.swift"; sourceTree = ""; }; D5907D962004B7EB005947E5 /* Account+Scriptability.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Account+Scriptability.swift"; sourceTree = ""; }; D5907DB12004BB37005947E5 /* ScriptingObjectContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScriptingObjectContainer.swift; sourceTree = ""; }; + D5A2678B20130ECF00A8D3C0 /* Author+Scriptability.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Author+Scriptability.swift"; sourceTree = ""; }; + D5A2679B201312F900A8D3C0 /* testNameOfAuthors.applescript */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.applescript; path = testNameOfAuthors.applescript; sourceTree = ""; }; D5D175012002039D0047B29D /* Evergreen.sdef */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = Evergreen.sdef; path = ../Resources/Evergreen.sdef; sourceTree = ""; }; D5F4EDB4200744A700B9E363 /* ScriptingObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScriptingObject.swift; sourceTree = ""; }; D5F4EDB620074D6500B9E363 /* Feed+Scriptability.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Feed+Scriptability.swift"; sourceTree = ""; }; @@ -1115,6 +1121,7 @@ D5907C9D20023249005947E5 /* testGenericScript.applescript */, D5558FD1200223F60066386B /* testGetURL.applescript */, D5F4EDE720075C1800B9E363 /* testNameAndUrlOfEveryFeed.applescript */, + D5A2679B201312F900A8D3C0 /* testNameOfAuthors.applescript */, D5F4EDD720075C1300B9E363 /* testNameOfEveryFolder.applescript */, ); path = scripts; @@ -1145,6 +1152,7 @@ isa = PBXGroup; children = ( D5907D962004B7EB005947E5 /* Account+Scriptability.swift */, + D5A2678B20130ECF00A8D3C0 /* Author+Scriptability.swift */, D5F4EDB620074D6500B9E363 /* Feed+Scriptability.swift */, D5F4EDB820074D7C00B9E363 /* Folder+Scriptability.swift */, D5907D7E2004AC00005947E5 /* NSApplication+Scriptability.swift */, @@ -1219,12 +1227,12 @@ TargetAttributes = { 849C645F1ED37A5D003D8FC0 = { CreatedOnToolsVersion = 8.2.1; - DevelopmentTeam = M8L2WTLA8W; - ProvisioningStyle = Manual; + DevelopmentTeam = 6V7D786XTL; + ProvisioningStyle = Automatic; }; 849C64701ED37A5D003D8FC0 = { CreatedOnToolsVersion = 8.2.1; - DevelopmentTeam = 9C84TZ7Q6Z; + DevelopmentTeam = 6V7D786XTL; ProvisioningStyle = Automatic; TestTargetID = 849C645F1ED37A5D003D8FC0; }; @@ -1549,6 +1557,7 @@ 84CC88181FE59CBF00644329 /* SmartFeedsController.swift in Sources */, 849A97661ED9EB96007D329B /* SidebarViewController.swift in Sources */, 849A97641ED9EB96007D329B /* SidebarOutlineView.swift in Sources */, + D5A2678C20130ECF00A8D3C0 /* Author+Scriptability.swift in Sources */, 84F2D5371FC22FCC00998D64 /* PseudoFeed.swift in Sources */, 845EE7C11FC2488C00854A1F /* SmartFeed.swift in Sources */, 84702AA41FA27AC0006B8943 /* MarkReadOrUnreadCommand.swift in Sources */, @@ -1624,6 +1633,7 @@ D5558FD5200225680066386B /* NSAppleEventDescriptor+UserRecordFields.swift in Sources */, D5558FD9200228D30066386B /* AppleEventUtils.swift in Sources */, D5907CA1200232A1005947E5 /* testGetURL.applescript in Sources */, + D5A2679C201312F900A8D3C0 /* testNameOfAuthors.applescript in Sources */, 849C64761ED37A5D003D8FC0 /* EvergreenTests.swift in Sources */, D5558FD32002245C0066386B /* ScriptingTests.swift in Sources */, D5F4EDE820075C1800B9E363 /* testNameAndUrlOfEveryFeed.applescript in Sources */, diff --git a/Evergreen/Resources/Evergreen.sdef b/Evergreen/Resources/Evergreen.sdef index 50a362990..6a3b6a98b 100644 --- a/Evergreen/Resources/Evergreen.sdef +++ b/Evergreen/Resources/Evergreen.sdef @@ -62,7 +62,7 @@ - + @@ -71,6 +71,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Evergreen/Scriptability/Author+Scriptability.swift b/Evergreen/Scriptability/Author+Scriptability.swift new file mode 100644 index 000000000..9f2ce5d90 --- /dev/null +++ b/Evergreen/Scriptability/Author+Scriptability.swift @@ -0,0 +1,71 @@ +// +// Author+Scriptability.swift +// Evergreen +// +// Created by Olof Hellman on 1/19/18. +// Copyright © 2018 Olof Hellman. All rights reserved. +// + +import Foundation +import Account +import Data + +@objc(ScriptableAuthor) +class ScriptableAuthor: NSObject, UniqueIdScriptingObject { + + let author:Author + let container:ScriptingObjectContainer + + init (_ author:Author, container:ScriptingObjectContainer) { + self.author = author + self.container = container + } + + @objc(objectSpecifier) + override var objectSpecifier: NSScriptObjectSpecifier? { + let scriptObjectSpecifier = self.container.makeFormUniqueIDScriptObjectSpecifier(forObject:self) + return (scriptObjectSpecifier) + } + + // MARK: --- ScriptingObject protocol --- + + var scriptingKey: String { + return "authors" + } + + // MARK: --- UniqueIdScriptingObject protocol --- + + // I am not sure if account should prefer to be specified by name or by ID + // but in either case it seems like the accountID would be used as the keydata, so I chose ID + + var scriptingUniqueId:Any { + return author.authorID + } + + // MARK: --- Scriptable properties --- + + @objc(url) + var url:String { + return self.author.url ?? "" + } + + @objc(uniqueId) + var uniqueId:String { + return self.author.authorID + } + + @objc(name) + var name:String { + return self.author.name ?? "" + } + + @objc(avatarURL) + var avatarURL:String { + return self.author.avatarURL ?? "" + } + + @objc(emailAddress) + var emailAddress:String { + return self.author.emailAddress ?? "" + } +} diff --git a/Evergreen/Scriptability/Feed+Scriptability.swift b/Evergreen/Scriptability/Feed+Scriptability.swift index 904297536..249270d3f 100644 --- a/Evergreen/Scriptability/Feed+Scriptability.swift +++ b/Evergreen/Scriptability/Feed+Scriptability.swift @@ -11,7 +11,7 @@ import Account import Data @objc(ScriptableFeed) -class ScriptableFeed: NSObject, UniqueIdScriptingObject { +class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectContainer{ let feed:Feed let container:ScriptingObjectContainer @@ -41,7 +41,13 @@ class ScriptableFeed: NSObject, UniqueIdScriptingObject { var scriptingUniqueId:Any { return feed.feedID } + + // MARK: --- ScriptingObjectContainer protocol --- + var scriptingClassDescription: NSScriptClassDescription { + return self.classDescription as! NSScriptClassDescription + } + // MARK: --- Scriptable properties --- @objc(url) @@ -59,4 +65,25 @@ class ScriptableFeed: NSObject, UniqueIdScriptingObject { return self.feed.name ?? "" } + @objc(homePageURL) + var homePageURL:String { + return self.feed.homePageURL ?? "" + } + + @objc(iconURL) + var iconURL:String { + return self.feed.iconURL ?? "" + } + + @objc(faviconURL) + var faviconURL:String { + return self.feed.faviconURL ?? "" + } + + @objc(authors) + var authors:NSArray { + let feedAuthors = feed.authors ?? [] + return feedAuthors.map { ScriptableAuthor($0, container:self) } as NSArray + } + } diff --git a/EvergreenTests/ScriptingTests/ScriptingTests.swift b/EvergreenTests/ScriptingTests/ScriptingTests.swift index 2ab49fee1..7dcd53c1c 100644 --- a/EvergreenTests/ScriptingTests/ScriptingTests.swift +++ b/EvergreenTests/ScriptingTests/ScriptingTests.swift @@ -57,7 +57,11 @@ class ScriptingTests: XCTestCase { } XCTAssert(testResult.booleanValue == true, "test_result should be true") - + if (testResult.booleanValue != true ) + { + print("test_result was \(testResult)") + print("script_result was \(String(describing: usrfDictionary["script_result"]))") + } return usrfDictionary["script_result"] } @@ -85,5 +89,9 @@ class ScriptingTests: XCTestCase { func testNameOfEveryFolderScript() { _ = doIndividualScript(filename: "testNameOfEveryFolder") } + + func testNameOfAuthorsScript() { + _ = doIndividualScript(filename: "testNameOfAuthors") + } } diff --git a/EvergreenTests/ScriptingTests/scripts/testNameOfAuthors.applescript b/EvergreenTests/ScriptingTests/scripts/testNameOfAuthors.applescript new file mode 100644 index 000000000..70cf352e9 --- /dev/null +++ b/EvergreenTests/ScriptingTests/scripts/testNameOfAuthors.applescript @@ -0,0 +1,12 @@ +-- this script just tests that no error was generated from the script +-- and that the returned list is greater than 0 +try + tell application "Evergreen" + set namesResult to name of every author of every feed of every account + end tell + set test_result to ((count items of namesResult) > 0) +on error message + return {test_result:false, script_result:message} +end try + +return {test_result:test_result}