Skip to content

Instantly share code, notes, and snippets.

@mikker
Created November 4, 2023 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikker/c847162db0ade5631053f68c52f60936 to your computer and use it in GitHub Desktop.
Save mikker/c847162db0ade5631053f68c52f60936 to your computer and use it in GitHub Desktop.
Add to Newsletters for Scriptable
{
"always_run_in_app" : false,
"icon" : {
"color" : "deep-purple",
"glyph" : "magic"
},
"name" : "Add to Newsletters",
"script" : "const input = args.plainTexts[0] || \"test@example.com\";\nconst emails = input.match(\/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z0-9._-]+)\/gi);\nconst email = emails[0];\n\n\nconst containers = await ContactsContainer.all();\n\nlet container, group;\nfor (const c of containers) {\n const groups = await ContactsGroup.all([c]);\n const newsletters = groups.find(g => g.name === \"Newsletters\");\n if (!newsletters) continue;\n container = c;\n group = newsletters;\n}\n\nconst contact = new Contact();\ncontact.emailAddresses =[{ value: email }];\nContact.add(contact, container.identifier);\ngroup.addMember(contact);\n\nawait Contact.persistChanges();\n\nconst alert = new Alert();\nalert.title = email;\nalert.addAction(\"OK\")\nalert.present();\n\n",
"share_sheet_inputs" : [
"plain-text"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment