【问题标题】:Parse NSAppleEventDescriptor in AppleScriptObjC在 AppleScriptObjC 中解析 NSAppleEventDescriptor
【发布时间】:2017-02-21 01:46:10
【问题描述】:

我正在尝试为 Automator 编写一个 AppleScript 应用程序来操作联系人组。我收到一个联系人项目作为脚本的输入,但我不知道如何解析它。这是我到目前为止写的源代码:

script Labels_for_contact_groups
    property parent : class "AMBundleAction"

    on runWithInput_fromAction_error_(input, anAction, errorRef)
        -- Get parameters
        set labelName to valueForKey_("trainingLabelName") of parameters() of me
        set labelValue to valueForKey_("trainingLabelValue") of parameters() of me

        -- Iterate over the contact groups
        -- what should I do here?
        log input

        return input
    end runWithInput_fromAction_error_
end script

我在日志中得到以下信息:

2016-10-12 11:35:28.061 Automator[2167:174553] <NSAppleEventDescriptor: [ 'obj '{ 'want':'azf5', 'form':'ID  ', 'seld':'utxt'("50E8C441-3DF0-4CD7-8E36-E175B37D2CCB:ABGroup"), 'from':[0x0,10d10d "Contacts"] } ]>

我需要做的是提取指定组中所有联系人的信息。我该如何进行?

编辑: 我添加了以下几行

tell application "Contacts" to set thePeople to people of input
repeat with i from 1 to number of items in thePeople
        set thisPersonCurrent to item i of thePeople
        log thisPersonCurrent
end repeat

现在我收到以下错误:

[Labels_for_contact_groups runWithInput:fromAction:error:]: Can’t get every «class azf4» of «class ocid» id «data optr0000000080A9220080600000». (error -1728)

我做错了什么?

【问题讨论】:

  • 在我看来,一个软件是一个应用程序或一个 Automator 操作。不能两者兼有。
  • input 是您的 Automator 操作的输入,它看起来像组 ID“50E8C441-3DF0-4CD7-8E36-E175B37D2CCB:ABGroup”。您可以像对待一个小组一样与输入交谈。
  • 这就是对象说明符(又名“引用”)被打包到 Apple 事件描述符中时的样子。您是否尝试过使用input as anything 将其强制回AppleScript 值?我唯一不知道的是,当你这样做时,引用是否会使用正确的应用程序——即联系人,而不是当前的应用程序——但你只需要尝试一下就可以了。 (坦率地说,Automator 系统和它被入侵的 AppleScript 钩子是一个糟糕的问题,但我认为你有理由想要使用它,而不是仅仅编写一个独立的 AS 小程序或#!/usr/bin/osascript shell 脚本。)

标签: xcode cocoa applescript applescript-objc


【解决方案1】:

我试图实现的目标无法通过 Automator 实现。我意识到 API 中存在许多差距。最终起作用的是具有以下行的独立 AppleScript:

tell application "Contacts"
  set theGroupNames to name of groups
  set text_returnedCurrent to choose from list theGroupNames with prompt "Select Group" without multiple selections allowed
  set the_peopleCurrent to people of group (text_returnedCurrent as text)
  ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多