summaryrefslogtreecommitdiff
path: root/.mutt/addcontact
blob: aa251d0505f034d9ec526101360aea131ee6ebd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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"