Skip to content

Instantly share code, notes, and snippets.

@craigeley
Created May 23, 2019 14:10
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigeley/9ef4073db18a9c9f18fd2b354fce4b3b to your computer and use it in GitHub Desktop.
Save craigeley/9ef4073db18a9c9f18fd2b354fce4b3b to your computer and use it in GitHub Desktop.
This script takes the contents of your clipboard, allows you to search for a contact, and then adds an Instagram social media profile to that contact. Useful for use with the Vignette iOS app and the "Connections.json" file from the Instagram data dump.
set input to the clipboard as text
--whole process is in a loop to allow for user to research for contact
repeat
--need to find contact in order to update their info
try
display dialog "Enter name or company of contact to Instagram to:" default answer ""
set thePerson to text returned of result
end try
if thePerson is not "" then --check that search was not blank
set parsed to parseLine(thePerson, space) --if user enters more than one word, only the first word is considered
if (count of parsed) is greater than 1 then set thePerson to item 1 of parsed
set nameList to {}
set idList to {}
--populate list of results based on user's search
tell application "Contacts"
set thePeople to every person whose first name contains thePerson or middle name contains thePerson or last name contains thePerson or organization contains thePerson
if (count of thePeople) is 0 then
try
display dialog "No contacts found! Search again."
on error
if closeAddressBook is true then quit
error -128
end try
else
--creating list of names of results for user to select from
repeat with x from 1 to count of thePeople
if the first name of item x of thePeople = missing value then
set tempFirst to ""
else
set tempFirst to the first name of item x of thePeople
end if
if the last name of item x of thePeople = missing value then
set tempLast to ""
else
set tempLast to the last name of item x of thePeople
end if
if the organization of item x of thePeople = missing value then
set tempOrg to ""
else
set tempOrg to the organization of item x of thePeople
end if
set tempString to tempFirst & " " & tempLast & " @ " & tempOrg
set end of nameList to tempString
set end of idList to the id of item x of thePeople
end repeat
--let user select contact to add number to
activate
set thePerson to choose from list nameList with prompt "Choose contact to add phone number to (choose cancel to search again)"
if thePerson is not false then exit repeat
end if
end tell
end if
end repeat
--loop back through result list to find contact that user selected
repeat with x from 1 to count of nameList
if thePerson as string = (item x of nameList as string) then
set theID to item x of idList
exit repeat
end if
end repeat
--populate list of phone number types for user to select
set theType to "Instagram"
--finally add the phone number of the selected or entered type to the contact
tell application "Contacts"
set thePerson to item 1 of (every person whose id is theID)
set theURL to "https://www.instagram.com/" & input & "/"
make new social profile at end of social profiles of thePerson with properties {service name:theType, user name:input, url:theURL}
save
end tell
return input
end run
--handler to parse lines of text
on parseLine(theLine, delimiter)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {delimiter}
set theTextItems to theLine's text items
set AppleScript's text item delimiters to astid
repeat with i from 1 to (count theTextItems)
if (item i of theTextItems is "") then set item i of theTextItems to missing value
end repeat
return theTextItems's every text
end parseLine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment