Advertisement
Guest User

Untitled

a guest
Jun 16th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. set nextLoop to "Stop"
  2. display dialog "Ready to go?  Selection should be on first item of first pair."
  3. if result's button returned is "OK" then
  4.     repeat 500 times
  5.         activate application "Microsoft Entourage"
  6.         tell application "System Events"
  7.             keystroke (ASCII character 31) using shift down
  8.         end tell
  9.         delay 0.5
  10.         activate application "Script Editor"
  11.         set mergeResult to mergeNow()
  12.         repeat while mergeResult is not "Match"
  13.             activate application "Microsoft Entourage"
  14.             tell application "System Events"
  15.                 keystroke (ASCII character 31)
  16.                 keystroke (ASCII character 30) using shift down
  17.             end tell
  18.             delay 0.5
  19.             activate application "Script Editor"
  20.             set mergeResult to mergeNow()
  21.         end repeat
  22.     end repeat
  23. end if
  24.  
  25. on mergeNow()
  26.     tell application "Microsoft Entourage"
  27.         -- basic error check, do we have two contacts selected?
  28.         set Sel to the selection
  29.         set Stype to class of (item 1 of Sel)
  30.         count Sel
  31.         if the result is not 2 or Stype is not contact then
  32.             error "You must select two and only two contacts to merge."
  33.             return
  34.         end if
  35.        
  36.         -- preserve the me contact, if one of the selected contacts is the me contact
  37.         -- else try to save the last received or sent information
  38.         if (me contact is (item 1 of Sel)) then
  39.             set contact1 to item 1 of Sel
  40.             set contact2 to item 2 of Sel
  41.         else if (me contact is (item 2 of Sel)) then
  42.             set contact2 to item 1 of Sel
  43.             set contact1 to item 2 of Sel
  44.         else if (last received date of (item 1 of Sel) ≠ date "Friday, January 1, 1904 12:00:00 AM") or ¬
  45.             (last sent date of (item 1 of Sel) ≠ date "Friday, January 1, 1904 12:00:00 AM") then
  46.             set contact1 to item 1 of Sel
  47.             set contact2 to item 2 of Sel
  48.         else
  49.             set contact2 to item 1 of Sel
  50.             set contact1 to item 2 of Sel
  51.         end if
  52.        
  53.         -- try to prevent unfortunate accidents by verifying the merge if the names are different
  54.         set mergecontacts to true
  55.         if (first name of contact1 ≠ first name of contact2) or ¬
  56.             (last name of contact1 ≠ last name of contact2) then
  57.             set mergecontacts to false
  58.         end if
  59.        
  60.         if mergecontacts = true then
  61.             --first name
  62.             set field_name to "First name"
  63.             set a to first name of contact1
  64.             set b to first name of contact2
  65.             set c to my mergefields(a, b, field_name)
  66.             if c ≠ a then set first name of contact1 to c
  67.            
  68.             set field_name to "First name furigana"
  69.             set a to first name furigana of contact1
  70.             set b to first name furigana of contact2
  71.             set c to my mergefields(a, b, field_name)
  72.             if c ≠ a then set first name furigana of contact1 to c
  73.             --Last name
  74.             set field_name to "Last name"
  75.             set a to last name of contact1
  76.             set b to last name of contact2
  77.             set c to my mergefields(a, b, field_name)
  78.             if c ≠ a then set last name of contact1 to c
  79.            
  80.             set field_name to "Last name furigana"
  81.             set a to last name furigana of contact1
  82.             set b to last name furigana of contact2
  83.             set c to my mergefields(a, b, field_name)
  84.             if c ≠ a then set last name furigana of contact1 to c
  85.             -- title
  86.             set field_name to "Title"
  87.             set a to title of contact1
  88.             set b to title of contact2
  89.             set c to my mergefields(a, b, field_name)
  90.             if c ≠ a then set title of contact1 to c
  91.             -- nickname
  92.             set field_name to "Nickname"
  93.             set a to nickname of contact1
  94.             set b to nickname of contact2
  95.             set c to my mergefields(a, b, field_name)
  96.             if c ≠ a then set nickname of contact1 to c
  97.             -- suffix
  98.             set field_name to "Suffix"
  99.             set a to suffix of contact1
  100.             set b to suffix of contact2
  101.             set c to my mergefields(a, b, field_name)
  102.             if c ≠ a then set suffix of contact1 to c
  103.             -- job title
  104.             set field_name to "Job title"
  105.             set a to job title of contact1
  106.             set b to job title of contact2
  107.             set c to my mergefields(a, b, field_name)
  108.             if c ≠ a then set job title of contact1 to c
  109.             -- company
  110.             set field_name to "Company"
  111.             set a to company of contact1
  112.             set b to company of contact2
  113.             set c to my mergefields(a, b, field_name)
  114.             if c ≠ a then set company of contact1 to c
  115.            
  116.             set field_name to "Company furigana"
  117.             set a to company furigana of contact1
  118.             set b to company furigana of contact2
  119.             set c to my mergefields(a, b, field_name)
  120.             if c ≠ a then set company furigana of contact1 to c
  121.             -- department
  122.             set field_name to "Department"
  123.             set a to department of contact1
  124.             set b to department of contact2
  125.             set c to my mergefields(a, b, field_name)
  126.             if c ≠ a then set department of contact1 to c
  127.             -- description
  128.             set field_name to "Description"
  129.             set a to description of contact1
  130.             set b to description of contact2
  131.             set c to my mergefields(a, b, field_name)
  132.             if c ≠ a then set description of contact1 to c
  133.             -- home web page
  134.             set field_name to "Home web page"
  135.             set a to home web page of contact1
  136.             set b to home web page of contact2
  137.             set c to my mergefields(a, b, field_name)
  138.             if c ≠ a then set home web page of contact1 to c
  139.             -- business web page
  140.             set field_name to "Business web page"
  141.             set a to business web page of contact1
  142.             set b to business web page of contact2
  143.             set c to my mergefields(a, b, field_name)
  144.             if c ≠ a then set business web page of contact1 to c
  145.            
  146.             -- E-mail addresses (a list)
  147.             set field_name to "E-mail addresses (a list)"
  148.             set a_mail to every email address of contact1
  149.             set b_mail to every email address of contact2
  150.             repeat with oneAddr in a_mail
  151.                 if oneAddr is not in b_mail then copy oneAddr to end of b_mail
  152.             end repeat
  153.             set a_count to count (a_mail)
  154.             repeat with i from 1 to (count b_mail)
  155.                 if i ≤ a_count then
  156.                     set contents of email address i of contact1 to (item i of b_mail)
  157.                 else
  158.                     make new email address of contact1 with data (item i of b_mail)
  159.                 end if
  160.             end repeat
  161.             -- Categories (a list of references)
  162.             set field_name to "Categories (a list)"
  163.             set a_cat to category of contact1
  164.             set b_cat to category of contact2
  165.             set b_name to {}
  166.             repeat with i from 1 to (count b_cat)
  167.                 copy name of item i of b_cat to end of b_name
  168.             end repeat
  169.             repeat with oneAddr in a_cat
  170.                 if name of oneAddr is not in b_name then copy oneAddr to end of b_cat
  171.             end repeat
  172.             if b_cat ≠ a_cat then set category of contact1 to b_cat
  173.             -- Home address fields
  174.             set field_name to "Home street address"
  175.             set a to street address of home address of contact1
  176.             set b to street address of home address of contact2
  177.             set c to my mergefields(a, b, field_name)
  178.             if c ≠ a then set street address of home address of contact1 to c
  179.             set field_name to "Home city"
  180.             set a to city of home address of contact1
  181.             set b to city of home address of contact2
  182.             set c to my mergefields(a, b, field_name)
  183.             if c ≠ a then set city of home address of contact1 to c
  184.             set field_name to "Home state"
  185.             set a to state of home address of contact1
  186.             set b to state of home address of contact2
  187.             set c to my mergefields(a, b, field_name)
  188.             if c ≠ a then set state of home address of contact1 to c
  189.             set field_name to "Home zip"
  190.             set a to zip of home address of contact1
  191.             set b to zip of home address of contact2
  192.             set c to my mergefields(a, b, field_name)
  193.             if c ≠ a then set zip of home address of contact1 to c
  194.             set field_name to "Home country"
  195.             set a to country of home address of contact1
  196.             set b to country of home address of contact2
  197.             set c to my mergefields(a, b, field_name)
  198.             if c ≠ a then set country of home address of contact1 to c
  199.             -- Business address fields
  200.             set field_name to "Business street address"
  201.             set a to street address of business address of contact1
  202.             set b to street address of business address of contact2
  203.             set c to my mergefields(a, b, field_name)
  204.             if c ≠ a then set street address of business address of contact1 to c
  205.             set field_name to "Business city"
  206.             set a to city of business address of contact1
  207.             set b to city of business address of contact2
  208.             set c to my mergefields(a, b, field_name)
  209.             if c ≠ a then set city of business address of contact1 to c
  210.             set field_name to "Business state"
  211.             set a to state of business address of contact1
  212.             set b to state of business address of contact2
  213.             set c to my mergefields(a, b, field_name)
  214.             if c ≠ a then set state of business address of contact1 to c
  215.             set field_name to "Business zip"
  216.             set a to zip of business address of contact1
  217.             set b to zip of business address of contact2
  218.             set c to my mergefields(a, b, field_name)
  219.             if c ≠ a then set zip of business address of contact1 to c
  220.             set field_name to "Business country"
  221.             set a to country of business address of contact1
  222.             set b to country of business address of contact2
  223.             set c to my mergefields(a, b, field_name)
  224.             if c ≠ a then set country of business address of contact1 to c
  225.             -- Birthday
  226.             set field_name to "Birthday"
  227.             set a to birthday of contact1
  228.             set b to birthday of contact2
  229.             set c to my mergefields(a, b, field_name)
  230.             if c ≠ a then set birthday of contact1 to c
  231.             -- age
  232.             set field_name to "Age"
  233.             set a to age of contact1
  234.             set b to age of contact2
  235.             set c to my mergefields(a, b, field_name)
  236.             if c ≠ a then set age of contact1 to c
  237.             -- home phone number
  238.             set field_name to "Home phone number"
  239.             set a to home phone number of contact1
  240.             set b to home phone number of contact2
  241.             set c to my mergefields(a, b, field_name)
  242.             if c ≠ a then set home phone number of contact1 to c
  243.             -- other home phone number
  244.             set field_name to "Other home phone number"
  245.             set a to other home phone number of contact1
  246.             set b to other home phone number of contact2
  247.             set c to my mergefields(a, b, field_name)
  248.             if c ≠ a then set other home phone number of contact1 to c
  249.             -- home fax phone number
  250.             set field_name to "Home fax phone number"
  251.             set a to home fax phone number of contact1
  252.             set b to home fax phone number of contact2
  253.             set c to my mergefields(a, b, field_name)
  254.             if c ≠ a then set home fax phone number of contact1 to c
  255.             -- business phone number
  256.             set field_name to "Business phone number"
  257.             set a to business phone number of contact1
  258.             set b to business phone number of contact2
  259.             set c to my mergefields(a, b, field_name)
  260.             if c ≠ a then set business phone number of contact1 to c
  261.             -- other business phone number
  262.             set field_name to "Other business phone number"
  263.             set a to other business phone number of contact1
  264.             set b to other business phone number of contact2
  265.             set c to my mergefields(a, b, field_name)
  266.             if c ≠ a then set other business phone number of contact1 to c
  267.             -- business fax phone number
  268.             set field_name to "Business fax phone number"
  269.             set a to business fax phone number of contact1
  270.             set b to business fax phone number of contact2
  271.             set c to my mergefields(a, b, field_name)
  272.             if c ≠ a then set business fax phone number of contact1 to c
  273.             -- main phone number
  274.             set field_name to "Main phone number"
  275.             set a to main phone number of contact1
  276.             set b to main phone number of contact2
  277.             set c to my mergefields(a, b, field_name)
  278.             if c ≠ a then set main phone number of contact1 to c
  279.             -- pager phone number
  280.             set field_name to "Pager phone number"
  281.             set a to pager phone number of contact1
  282.             set b to pager phone number of contact2
  283.             set c to my mergefields(a, b, field_name)
  284.             if c ≠ a then set pager phone number of contact1 to c
  285.             -- mobile phone number
  286.             set field_name to "Mobile phone number"
  287.             set a to mobile phone number of contact1
  288.             set b to mobile phone number of contact2
  289.             set c to my mergefields(a, b, field_name)
  290.             if c ≠ a then set mobile phone number of contact1 to c
  291.             -- assistant phone number
  292.             set field_name to "Assistant phone number"
  293.             set a to assistant phone number of contact1
  294.             set b to assistant phone number of contact2
  295.             set c to my mergefields(a, b, field_name)
  296.             if c ≠ a then set assistant phone number of contact1 to c
  297.             --  custom phone number one
  298.             set field_name to "Custom phone number one"
  299.             set a to custom phone number one of contact1
  300.             set b to custom phone number one of contact2
  301.             set c to my mergefields(a, b, field_name)
  302.             if c ≠ a then set custom phone number one of contact1 to c
  303.             --  custom phone number two
  304.             set field_name to "Custom phone number two"
  305.             set a to custom phone number two of contact1
  306.             set b to custom phone number two of contact2
  307.             set c to my mergefields(a, b, field_name)
  308.             if c ≠ a then set custom phone number two of contact1 to c
  309.             --  custom phone number three
  310.             set field_name to "Custom phone number three"
  311.             set a to custom phone number three of contact1
  312.             set b to custom phone number three of contact2
  313.             set c to my mergefields(a, b, field_name)
  314.             if c ≠ a then set custom phone number three of contact1 to c
  315.             --  custom phone number four
  316.             set field_name to "Custom phone number four"
  317.             set a to custom phone number four of contact1
  318.             set b to custom phone number four of contact2
  319.             set c to my mergefields(a, b, field_name)
  320.             if c ≠ a then set custom phone number four of contact1 to c
  321.             -- custom field one
  322.             set field_name to "Custom field one"
  323.             set a to custom field one of contact1
  324.             set b to custom field one of contact2
  325.             set c to my mergefields(a, b, field_name)
  326.             if c ≠ a then set custom field one of contact1 to c
  327.             -- custom field two
  328.             set field_name to "Custom field two"
  329.             set a to custom field two of contact1
  330.             set b to custom field two of contact2
  331.             set c to my mergefields(a, b, field_name)
  332.             if c ≠ a then set custom field two of contact1 to c
  333.             -- custom field three
  334.             set field_name to "Custom field three"
  335.             set a to custom field three of contact1
  336.             set b to custom field three of contact2
  337.             set c to my mergefields(a, b, field_name)
  338.             if c ≠ a then set custom field three of contact1 to c
  339.             -- custom field four
  340.             set field_name to "Custom field four"
  341.             set a to custom field four of contact1
  342.             set b to custom field four of contact2
  343.             set c to my mergefields(a, b, field_name)
  344.             if c ≠ a then set custom field four of contact1 to c
  345.             -- custom field five
  346.             set field_name to "Custom field five"
  347.             set a to custom field five of contact1
  348.             set b to custom field five of contact2
  349.             set c to my mergefields(a, b, field_name)
  350.             if c ≠ a then set custom field five of contact1 to c
  351.             -- custom field six
  352.             set field_name to "Custom field six"
  353.             set a to custom field six of contact1
  354.             set b to custom field six of contact2
  355.             set c to my mergefields(a, b, field_name)
  356.             if c ≠ a then set custom field six of contact1 to c
  357.             -- custom field seven
  358.             set field_name to "Custom field seven"
  359.             set a to custom field seven of contact1
  360.             set b to custom field seven of contact2
  361.             set c to my mergefields(a, b, field_name)
  362.             if c ≠ a then set custom field seven of contact1 to c
  363.             -- custom field eight
  364.             set field_name to "Custom field eight"
  365.             set a to custom field eight of contact1
  366.             set b to custom field eight of contact2
  367.             set c to my mergefields(a, b, field_name)
  368.             if c ≠ a then set custom field eight of contact1 to c
  369.             -- astrology sign
  370.             set field_name to "Astrology sign"
  371.             set a to astrology sign of contact1
  372.             set b to astrology sign of contact2
  373.             set c to my mergefields(a, b, field_name)
  374.             if c ≠ a then set astrology sign of contact1 to c
  375.             -- spouse
  376.             set field_name to "Spouse"
  377.             set a to spouse of contact1
  378.             set b to spouse of contact2
  379.             set c to my mergefields(a, b, field_name)
  380.             if c ≠ a then set spouse of contact1 to c
  381.             set field_name to "Spouse furigana"
  382.             set a to spouse furigana of contact1
  383.             set b to spouse furigana of contact2
  384.             set c to my mergefields(a, b, field_name)
  385.             if c ≠ a then set spouse furigana of contact1 to c
  386.             -- interests
  387.             set field_name to "Interests"
  388.             set a to interests of contact1
  389.             set b to interests of contact2
  390.             set c to my mergefields(a, b, field_name)
  391.             if c ≠ a then set interests of contact1 to c
  392.             -- blood type
  393.             set field_name to "Blood type"
  394.             set a to blood type of contact1
  395.             set b to blood type of contact2
  396.             set c to my mergefields(a, b, field_name)
  397.             if c ≠ a then set blood type of contact1 to c
  398.             -- custom date field one
  399.             set field_name to "Custom date field one"
  400.             set a to custom date field one of contact1
  401.             set b to custom date field one of contact2
  402.             set c to my mergefields(a, b, field_name)
  403.             if c ≠ a then set custom date field one of contact1 to c
  404.             -- custom date field two
  405.             set field_name to "Custom date field two"
  406.             set a to custom date field two of contact1
  407.             set b to custom date field two of contact2
  408.             set c to my mergefields(a, b, field_name)
  409.             if c ≠ a then set custom date field two of contact1 to c
  410.             -- anniversary
  411.             set field_name to "Anniversary"
  412.             set a to anniversary of contact1
  413.             set b to anniversary of contact2
  414.             set c to my mergefields(a, b, field_name)
  415.             if c ≠ a then set anniversary of contact1 to c
  416.             -- children (a list of strings)
  417.             set field_name to "Children's names"
  418.             set a_children to children of contact1
  419.             set b_children to children of contact2
  420.             repeat with child in a_children
  421.                 if b_children does not contain child then set b_children to (child as list) & b_children
  422.             end repeat
  423.             set children of contact1 to b_children
  424.            
  425.             -- Japanese format
  426.             set field_name to "Japanese format"
  427.             set a to Japanese format of contact1
  428.             set b to Japanese format of contact2
  429.             set c to my mergefields(a, b, field_name)
  430.             if c ≠ a then set Japanese format of contact1 to c
  431.             --  say "Merge complete."
  432.             delete contact2
  433.             beep
  434.         else
  435.             return "No Match"
  436.         end if
  437.     end tell
  438.     return "Match"
  439. end mergeNow
  440.  
  441. on mergefields(a, b, field_name)
  442.     if a ≠ b then
  443.         if a = "" then
  444.             return b
  445.         else if b = "" then
  446.             return a
  447.         else
  448.             if length of (a as string) > 100 then
  449.                 set a_brief to text 1 thru 100 of a as string
  450.             else
  451.                 set a_brief to a
  452.             end if
  453.             if length of (b as string) > 100 then
  454.                 set b_brief to text 1 thru 100 of b as string
  455.             else
  456.                 set b_brief to b
  457.             end if
  458.             display dialog "For field " & field_name & ¬
  459.                 ", Choose A, B, or More Choices to merge or enter new data" & return ¬
  460.                 & "A: " & a_brief & return & "B: " & b_brief & return ¬
  461.                 buttons {"A", "B", "More Choices"} default button 1
  462.             set pressed to button returned of result
  463.             if pressed is "A" then return a
  464.             if pressed is "B" then return b
  465.             display dialog "For field " & field_name & ¬
  466.                 ", Choose Merge to merge the fields, or Enter New Data" & return ¬
  467.                 & "A: " & a_brief & return & "B: " & b_brief & return & "New Data:" & return ¬
  468.                 buttons {"Merge", "Enter New Data"} default button 1 ¬
  469.                 default answer ""
  470.             set {pressed, ans} to {button returned of result, text returned of result}
  471.             if pressed is "Merge" then return a & " " & b
  472.             -- New data
  473.             return ans
  474.         end if
  475.     else
  476.         return a
  477.     end if
  478. end mergefields
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement