2018-03-05 03:43:29 +01:00
|
|
|
//
|
2018-08-29 07:18:24 +02:00
|
|
|
// NSScriptCommand+NetNewsWire.swift
|
|
|
|
// NetNewsWire
|
2018-03-05 03:43:29 +01:00
|
|
|
//
|
|
|
|
// Created by Olof Hellman on 3/4/18.
|
2018-03-05 04:01:58 +01:00
|
|
|
// Copyright © 2018 Olof Hellman. All rights reserved.
|
2018-03-05 03:43:29 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import Account
|
|
|
|
|
|
|
|
extension NSScriptCommand {
|
|
|
|
func property(forKey key:String) -> Any? {
|
|
|
|
if let evaluatedArguments = self.evaluatedArguments {
|
|
|
|
if let props = evaluatedArguments["KeyDictionary"] as? [String: Any] {
|
|
|
|
return props[key]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func isCreateCommand(forClass whatClass:String) -> Bool {
|
|
|
|
guard let arguments = self.arguments else {return false}
|
|
|
|
guard let newObjectClass = arguments["ObjectClass"] as? Int else {return false}
|
2019-04-13 21:58:43 +02:00
|
|
|
guard (newObjectClass.fourCharCode() == whatClass.fourCharCode()) else {return false}
|
2018-03-05 03:43:29 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func accountAndFolderForNewChild() -> (Account, Folder?) {
|
|
|
|
let appleEvent = self.appleEvent
|
2019-05-01 12:53:18 +02:00
|
|
|
var account = AccountManager.shared.defaultAccount
|
2018-03-05 03:43:29 +01:00
|
|
|
var folder:Folder? = nil
|
|
|
|
if let appleEvent = appleEvent {
|
|
|
|
var descriptorToConsider:NSAppleEventDescriptor?
|
|
|
|
if let insertionLocationDescriptor = appleEvent.paramDescriptor(forKeyword:keyAEInsertHere) {
|
|
|
|
print("insertionLocation : \(insertionLocationDescriptor)")
|
|
|
|
// insertion location can be a typeObjectSpecifier, e.g. 'in account "Acct"'
|
|
|
|
// or a typeInsertionLocation, e.g. 'at end of folder "
|
2019-04-13 21:58:43 +02:00
|
|
|
if (insertionLocationDescriptor.descriptorType == "insl".fourCharCode()) {
|
|
|
|
descriptorToConsider = insertionLocationDescriptor.forKeyword("kobj".fourCharCode())
|
|
|
|
} else if ( insertionLocationDescriptor.descriptorType == "obj ".fourCharCode()) {
|
2018-03-05 03:43:29 +01:00
|
|
|
descriptorToConsider = insertionLocationDescriptor
|
|
|
|
}
|
2019-04-13 21:58:43 +02:00
|
|
|
} else if let subjectDescriptor = appleEvent.attributeDescriptor(forKeyword:"subj".fourCharCode()) {
|
2018-03-05 03:43:29 +01:00
|
|
|
descriptorToConsider = subjectDescriptor
|
|
|
|
}
|
|
|
|
|
|
|
|
if let descriptorToConsider = descriptorToConsider {
|
|
|
|
guard let newContainerSpecifier = NSScriptObjectSpecifier(descriptor:descriptorToConsider) else {return (account, folder)}
|
|
|
|
let newContainer = newContainerSpecifier.objectsByEvaluatingSpecifier
|
|
|
|
if let scriptableAccount = newContainer as? ScriptableAccount {
|
|
|
|
account = scriptableAccount.account
|
|
|
|
} else if let scriptableFolder = newContainer as? ScriptableFolder {
|
|
|
|
if let folderAccount = scriptableFolder.folder.account {
|
|
|
|
folder = scriptableFolder.folder
|
|
|
|
account = folderAccount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (account, folder)
|
|
|
|
}
|
|
|
|
}
|