summaryrefslogtreecommitdiff
path: root/.mutt/addcontact
diff options
context:
space:
mode:
Diffstat (limited to '.mutt/addcontact')
-rw-r--r--.mutt/addcontact54
1 files changed, 54 insertions, 0 deletions
diff --git a/.mutt/addcontact b/.mutt/addcontact
new file mode 100644
index 0000000..aa251d0
--- /dev/null
+++ b/.mutt/addcontact
@@ -0,0 +1,54 @@
+#!/bin/bash
+osascript -e "tell application \"Address Book\"" \
+-e " set firstParam to \"$1\"" \
+-e " set secondParam to \"$2\"" \
+-e " set thirdParam to \"$3\"" \
+-e " set fourthParam to \"$4\"" \
+-e " set contactEmailLabel to \"\"" \
+-e " set spaceOffset to (offset of \" \" in firstParam)" \
+-e " if (spaceOffset is not equal to 0) then" \
+-e " set AppleScript's text item delimiters to \" \"" \
+-e " set firstName to (text item 1 of firstParam)" \
+-e " set lastName to (text item 2 of firstParam)" \
+-e " set firstEmailParam to secondParam" \
+-e " set secondEmailParam to thirdParam" \
+-e " else" \
+-e " set firstName to firstParam" \
+-e " set lastName to secondParam" \
+-e " set firstEmailParam to thirdParam" \
+-e " set secondEmailParam to fourthParam" \
+-e " end if" \
+-e " set atOffset to (offset of \"@\" in firstEmailParam)" \
+-e " if (atOffset is not equal to 0) then" \
+-e " set contactEmail to firstEmailParam" \
+-e " else" \
+-e " set contactEmailLabel to firstEmailParam" \
+-e " set contactEmail to secondEmailParam" \
+-e " end if" \
+-e " set bracketOffset to (offset of \"<\" in contactEmail)" \
+-e " if (bracketOffset is not equal to 0) then" \
+-e " set contactEmail to text 2 thru -2 of contactEmail" \
+-e " end if" \
+-e " if (contactEmailLabel is equal to \"\") then" \
+-e " set contactEmailLabel to \"Home\"" \
+-e " end if" \
+-e " set newPerson to (make new person with properties {first name:firstName, last name:lastName})" \
+-e " make new email at end of emails of newPerson with properties {label:contactEmailLabel, value:contactEmail}" \
+-e " save" \
+-e " if (newPerson exists) then" \
+-e " if (firstName exists) then" \
+-e " set returnString to (\"First name: \" & firstName)" \
+-e " end if" \
+-e " if (lastName exists) then" \
+-e " set returnString to (returnString & \"; Last name: \" & lastName)" \
+-e " end if" \
+-e " if (contactEmailLabel exists) then" \
+-e " set returnString to (returnString & \"; Email label: \" & contactEmailLabel)" \
+-e " end if" \
+-e " if (contactEmail exists) then" \
+-e " set returnString to (returnString & \"; Email address: \" & contactEmail)" \
+-e " end if" \
+-e " return returnString" \
+-e " end if" \
+-e "end tell"
+