Skip to content

Instantly share code, notes, and snippets.

@toco
Created October 1, 2015 14:06
Show Gist options
  • Save toco/e51ae00e0473b23802e7 to your computer and use it in GitHub Desktop.
Save toco/e51ae00e0473b23802e7 to your computer and use it in GitHub Desktop.
Apple Script to migrate old e-mail aliases (which where lost when upgrading to El Capitan) to Mail 9.0.
tell application "System Events"
set plistFile to property list file "~/Library/Mail/V2/MailData/Accounts.plist"
set plistRoot to contents of plistFile
tell plistRoot to set accountsPlist to value of property list item "MailAccounts"
end tell
tell application "Mail"
repeat with accPlist in accountsPlist
set accName to ""
try
set accName to get AccountName of accPlist
end try
repeat with acc in accounts
if accName = name of acc then
set plistAddresses to EmailAddresses of accPlist
set accAddresses to email addresses of acc
if (count of plistAddresses) ≤ 1 then
exit repeat
end if
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to ", "
set plistString to plistAddresses as string
set accString to accAddresses as string
set AppleScript's text item delimiters to oldDelimiters
if accString = plistString then
exit repeat
end if
set replaceReturn to display dialog "Replace
" & accString & "
with
" & plistString & "
?" buttons {"No", "Yes"}
if button returned of replaceReturn is "Yes" then
set email addresses of acc to plistAddresses as list
end if
exit repeat
end if
end repeat
end repeat
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment