Created
December 15, 2018 21:46
-
-
Save purp/05c8f126a5288c43ae65d9a7e5b9c557 to your computer and use it in GitHub Desktop.
Revisions
-
purp created this gist
Dec 15, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ I have a bunch of folks I want to export from Apple Contacts on MacOS and turn into a spreadsheet for a holiday card mail merge. This is my clumsy way of doing it. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ require 'vpim' require 'csv' module Vpim class Vcard def full_name name.fullname.to_s end class Address def street_address ("%s, %s %s %s" % [street, locality, region, postalcode]).strip end end def street_address address ? address.street_address.to_s : nil end def email_address email.to_s end def phone_number telephone.to_s end def mail_merge_fields [full_name, street_address, email_address, phone_number] end end end output_filename = ARGV[0].nil? ? 'mail_merge_output.csv' : "#{File.basename(ARGV[0])}.csv" vcf = ARGV[0].nil? ? STDIN : open(ARGV[0]) cards = Vpim::Vcard.decode(vcf) csv_rows = [["Name", "Address", "Email", "Phone"]] + cards.map(&:mail_merge_fields) open(output_filename, "w") { |csv| csv.write(csv_rows.map(&:to_csv).join) }