2

I am trying to write an AppleScript application for the Automator to manipulate Contact groups. I am receiving a contact item as input to the script but I'm stuck at how to parse it. Here's the source I've written so far:

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

I get the following in the logs:

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"] } ]>

What I need to do is extract the information of all contacts in the specified group. How do I proceed?

Edit: I added the following lines

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

Now I get the following error:

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

What am I doing wrong?

  • In my mind a piece of software is an application or an Automator action. It can't be both. – Willeke Oct 12 '16 at 12:29
  • `input` is the input of your Automator action and it looks like group id "50E8C441-3DF0-4CD7-8E36-E175B37D2CCB:ABGroup". You can talk to input as if it were a group. – Willeke Oct 12 '16 at 12:42
  • That's what an object specifier (aka 'reference') looks like when it's packed into an Apple event descriptor. Have you tried coercing it back to an AppleScript value using `input as anything`? The only thing I don't know is if the reference'll use the correct application when you do – i.e. Contacts, not the current application – but you'll just have to try it and see. (Frankly the Automator system and its hacked-in AppleScript hooks are a grotty bodge, but I assume you've a reason for wanting to use it rather than just writing a standalone AS applet or `#!/usr/bin/osascript` shell script.) – foo Oct 12 '16 at 12:57

1 Answers1

0

What I was trying to achieve did not work through the Automator. I realised there are numerous gaps in the API. What finally worked was a standalone AppleScript with the following line:

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)
  ...