Skip to content

Instantly share code, notes, and snippets.

@henrahmagix
Last active September 22, 2018 12:37
Show Gist options
  • Save henrahmagix/7b8909a02dcd326aa29dcd46be1dd8c6 to your computer and use it in GitHub Desktop.
Save henrahmagix/7b8909a02dcd326aa29dcd46be1dd8c6 to your computer and use it in GitHub Desktop.
Unmarshaling a Workflow plist in Go
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>WFWorkflowActions</key>
<array>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.gettext</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>UUID</key>
<string>74281268-1E67-4549-97A6-72BCB63C5FEF</string>
<key>WFTextActionText</key>
<string>City 1, state 1,country 1
City 2,country 2
City 3,state 3, country 3</string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.text.split</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>UUID</key>
<string>71AD13FE-B65D-4E08-9E3D-CB3F66C40269</string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.repeat.each</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>GroupingIdentifier</key>
<string>B75F287F-EB1C-460A-B1DE-11D60B2BAB11</string>
<key>WFControlFlowMode</key>
<integer>0</integer>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.text.match</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>UUID</key>
<string>65F04DCF-038F-41C6-A280-864ECCD34295</string>
<key>WFMatchTextCaseSensitive</key>
<false/>
<key>WFMatchTextPattern</key>
<string>((?:[^,])+)</string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.text.match.getgroup</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>UUID</key>
<string>9B1E0CB9-255D-4FA3-8D20-4FE7B7C73B06</string>
<key>WFGetGroupType</key>
<string>All Groups</string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.setvariable</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>WFVariableName</key>
<string>Columns</string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.getitemfromlist</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>UUID</key>
<string>35F562B5-9978-4058-9BB7-B305A94F1A89</string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.text.replace</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>WFReplaceTextCaseSensitive</key>
<false/>
<key>WFReplaceTextFind</key>
<string>^\s+|\s+$</string>
<key>WFReplaceTextRegularExpression</key>
<true/>
<key>WFReplaceTextReplace</key>
<string></string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.setvariable</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>WFVariableName</key>
<string>City</string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.getvariable</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>WFVariable</key>
<dict>
<key>Value</key>
<dict>
<key>Type</key>
<string>Variable</string>
<key>VariableName</key>
<string>Columns</string>
</dict>
<key>WFSerializationType</key>
<string>WFTextTokenAttachment</string>
</dict>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.count</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>UUID</key>
<string>FC834E86-07C4-4544-86EA-839C5F61336B</string>
<key>WFCountType</key>
<string>Items</string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.conditional</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>GroupingIdentifier</key>
<string>625CBD3A-4E12-469B-A214-AA574E781078</string>
<key>WFCondition</key>
<string>Equals</string>
<key>WFConditionalActionString</key>
<string>3</string>
<key>WFControlFlowMode</key>
<integer>0</integer>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.getvariable</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>WFVariable</key>
<dict>
<key>Value</key>
<dict>
<key>Type</key>
<string>Variable</string>
<key>VariableName</key>
<string>Columns</string>
</dict>
<key>WFSerializationType</key>
<string>WFTextTokenAttachment</string>
</dict>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.getitemfromlist</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>UUID</key>
<string>CEF27067-861F-4FC4-8ACC-18A3E646A452</string>
<key>WFItemIndex</key>
<real>2</real>
<key>WFItemSpecifier</key>
<string>Item At Index</string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.text.replace</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>WFReplaceTextCaseSensitive</key>
<false/>
<key>WFReplaceTextFind</key>
<string>^\s+|\s+$</string>
<key>WFReplaceTextRegularExpression</key>
<true/>
<key>WFReplaceTextReplace</key>
<string></string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.setvariable</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>WFVariableName</key>
<string>State</string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.getvariable</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>WFVariable</key>
<dict>
<key>Value</key>
<dict>
<key>Type</key>
<string>Variable</string>
<key>VariableName</key>
<string>Columns</string>
</dict>
<key>WFSerializationType</key>
<string>WFTextTokenAttachment</string>
</dict>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.getitemfromlist</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>UUID</key>
<string>47EF213B-6CC8-43BB-BF9B-36698ABE349A</string>
<key>WFItemIndex</key>
<real>3</real>
<key>WFItemSpecifier</key>
<string>Item At Index</string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.text.replace</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>WFReplaceTextCaseSensitive</key>
<false/>
<key>WFReplaceTextFind</key>
<string>^\s+|\s+$</string>
<key>WFReplaceTextRegularExpression</key>
<true/>
<key>WFReplaceTextReplace</key>
<string></string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.setvariable</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>WFVariableName</key>
<string>Country</string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.conditional</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>GroupingIdentifier</key>
<string>625CBD3A-4E12-469B-A214-AA574E781078</string>
<key>WFControlFlowMode</key>
<integer>1</integer>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.getvariable</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>WFVariable</key>
<dict>
<key>Value</key>
<dict>
<key>Type</key>
<string>Variable</string>
<key>VariableName</key>
<string>Columns</string>
</dict>
<key>WFSerializationType</key>
<string>WFTextTokenAttachment</string>
</dict>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.getitemfromlist</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>UUID</key>
<string>22776BA7-0BD7-4F49-B08B-EBB7C9CD3E0B</string>
<key>WFItemIndex</key>
<real>2</real>
<key>WFItemSpecifier</key>
<string>Item At Index</string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.text.replace</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>UUID</key>
<string>7815B5D9-6048-4690-83D4-7B232249AC00</string>
<key>WFReplaceTextCaseSensitive</key>
<false/>
<key>WFReplaceTextFind</key>
<string>^\s+|\s+$</string>
<key>WFReplaceTextRegularExpression</key>
<true/>
<key>WFReplaceTextReplace</key>
<string></string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.setvariable</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>WFVariableName</key>
<string>Country</string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.gettext</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>UUID</key>
<string>E2D1A13D-52B7-4C66-8BCC-B27AA39ABD10</string>
<key>WFTextActionText</key>
<string>N/A</string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.setvariable</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>WFVariableName</key>
<string>State</string>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.conditional</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>GroupingIdentifier</key>
<string>625CBD3A-4E12-469B-A214-AA574E781078</string>
<key>UUID</key>
<string>E941CF82-150F-4A43-9F57-8F66B8E97C13</string>
<key>WFControlFlowMode</key>
<integer>2</integer>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.gettext</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>UUID</key>
<string>A0527725-3A10-448A-A19E-C203D0F05E71</string>
<key>WFTextActionText</key>
<dict>
<key>Value</key>
<dict>
<key>attachmentsByRange</key>
<dict>
<key>{13, 1}</key>
<dict>
<key>Type</key>
<string>Variable</string>
<key>VariableName</key>
<string>State</string>
</dict>
<key>{23, 1}</key>
<dict>
<key>Type</key>
<string>Variable</string>
<key>VariableName</key>
<string>Country</string>
</dict>
<key>{5, 1}</key>
<dict>
<key>Type</key>
<string>Variable</string>
<key>VariableName</key>
<string>City</string>
</dict>
</dict>
<key>string</key>
<string>City= State= Country=</string>
</dict>
<key>WFSerializationType</key>
<string>WFTextTokenString</string>
</dict>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.repeat.each</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>GroupingIdentifier</key>
<string>B75F287F-EB1C-460A-B1DE-11D60B2BAB11</string>
<key>WFControlFlowMode</key>
<integer>2</integer>
</dict>
</dict>
<dict>
<key>WFWorkflowActionIdentifier</key>
<string>is.workflow.actions.text.combine</string>
<key>WFWorkflowActionParameters</key>
<dict>
<key>WFTextSeparator</key>
<string>New Lines</string>
</dict>
</dict>
</array>
<key>WFWorkflowClientRelease</key>
<string>1.7.8</string>
<key>WFWorkflowClientVersion</key>
<string>508</string>
<key>WFWorkflowIcon</key>
<dict>
<key>WFWorkflowIconGlyphNumber</key>
<integer>59511</integer>
<key>WFWorkflowIconImageData</key>
<data>
</data>
<key>WFWorkflowIconStartColor</key>
<integer>4271458815</integer>
</dict>
<key>WFWorkflowImportQuestions</key>
<array/>
<key>WFWorkflowInputContentItemClasses</key>
<array>
<string>WFAppStoreAppContentItem</string>
<string>WFArticleContentItem</string>
<string>WFContactContentItem</string>
<string>WFDateContentItem</string>
<string>WFEmailAddressContentItem</string>
<string>WFGenericFileContentItem</string>
<string>WFImageContentItem</string>
<string>WFiTunesProductContentItem</string>
<string>WFLocationContentItem</string>
<string>WFDCMapsLinkContentItem</string>
<string>WFAVAssetContentItem</string>
<string>WFPDFContentItem</string>
<string>WFPhoneNumberContentItem</string>
<string>WFRichTextContentItem</string>
<string>WFSafariWebPageContentItem</string>
<string>WFStringContentItem</string>
<string>WFURLContentItem</string>
</array>
<key>WFWorkflowTypes</key>
<array/>
</dict>
</plist>
package main
import (
"fmt"
"io/ioutil"
"os"
"github.com/groob/plist"
)
type Workflow struct {
Actions []*WorkflowAction `plist:"WFWorkflowActions"`
}
type WorkflowAction struct {
ID string `plist:"WFWorkflowActionIdentifier"`
Parameters *WorkflowParameter `plist:"WFWorkflowActionParameters"`
}
type WorkflowParameter struct {
GroupingIdentifier string
UUID string
WFCondition string
WFConditionalActionString string
WFControlFlowMode int
WFCountType string
WFGetGroupType string
WFItemIndex float32
WFItemSpecifier string
WFMatchTextCaseSensitive bool
WFMatchTextPattern string
WFReplaceTextCaseSensitive bool
WFReplaceTextFind string
WFReplaceTextRegularExpression bool
WFReplaceTextReplace string
WFTextActionText string // can also be <dict> :confused:
WFTextSeparator string
WFVariable *WFVariable
WFVariableName string
}
type WFVariable struct {
Value *Value
WFSerializationType string
}
type Value struct {
Type string
VariableName string
AttachmentsByRange map[string]*Value `plist:"attachmentsByRange"`
String string `plist:"string"`
}
func (w *WorkflowParameter) UnmarshalPlist(fn func(interface{}) error) error {
fmt.Println("unmarshaling custom")
err := fn(w)
if err != nil {
fmt.Printf("err=%#v\n", err)
}
return err
}
func Load(file string) (*Workflow, error) {
input, err := os.Open(file)
if err != nil {
return nil, err
}
stream, err := ioutil.ReadAll(input)
if err != nil {
return nil, err
}
data := new(Workflow)
err = plist.Unmarshal(stream, data)
return data, err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment