Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Batch append/remove data in the Notes field on Address Book cards' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Batch append/remove data in the Notes field on Address Book cards
Authored by: reeks on Feb 28, '12 02:21:48PM

I combined two scripts to be able to batch remove strings from the notes but leave the rest of the notes intact. If you remove nothing, it will remove the entire note (as the script in the comments above.

I find this to be useful in combination with smart groups. Use at your own risk of course.

property delim : ";" -- this is the delimiter used to separate notes.

set theDialogResult to display dialog "Enter note value, and select Add or Delete to add/remove that note from the selected Address Book cards." default answer "" buttons {"Add", "Remove", "Cancel"} default button 1
set {theAction, theString} to {button returned, text returned} of theDialogResult
if theString is "" then
-- if it's an empty string skip for adds, confirm clear all for deletes
if theAction is "Add" then return
if theAction is "Remove" then
display alert "Delete all?" message "Are you sure that you want to clear all notes from the selected messages?" buttons {"OK", "Cancel"} default button "Cancel" as warning
if button returned of the result is "Cancel" then return
end if
end if

tell application "Address Book"
set thePeople to selection
repeat with thePerson in thePeople
if theAction is "Add" then
set noteValue to note of thePerson
if noteValue is in {missing value, space} then set noteValue to ""
set {tid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, delim}
set noteList to text items of noteValue
if theString is not in text items of noteValue then
set end of noteList to theString
end if
set newNoteValue to noteList as text
set AppleScript's text item delimiters to tid
set note of thePerson to newNoteValue
else if theAction is "Remove" then
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, theString}
set n to text items of (get note of thePerson)
set AppleScript's text item delimiters to ASTID
set note of contents of thePerson to n as text
save thePerson
end if
end repeat
save
return
end tell



[ Reply to This | # ]