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


Click here to return to the 'Batch append data to 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 data to the Notes field on Address Book cards
Authored by: tedw on May 23, '10 07:49:01PM
here's an expanded and somewhat cleaner version of the script. This allows adding or deleting individual notes, as well as clearing the entire note list for the selected items.
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", "Delete", "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 "Delete" 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
		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}
		if theAction is "Add" then
			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
		else if theAction is "Delete" then
			set noteList to {}
			if theString is not "" then
				repeat with thisNote in (text items of noteValue)
					set thisNote to contents of thisNote
					if thisNote is not theString then
						set end of noteList to thisNote
					end if
				end repeat
			end if
		end if
		set newNoteValue to noteList as text
		set AppleScript's text item delimiters to tid
		set note of thePerson to newNoteValue
	end repeat
	save
end tell
The reason you were getting a 'missing value' result in Script Editor is that the 'save' command is a shortcut for 'save addressbook', and is used to save the entire book. It does not return a result (hence the 'missing value' result that you're seeing). I'm actually surprised your version not throwing an error - 'save thePerson' is meaningless in context - but no sense looking a gift horse in the mouth.

[ Reply to This | # ]
Batch append data to the Notes field on Address Book cards
Authored by: misterlink on May 23, '10 08:50:06PM

Thanks for posting - that's handy to have the add and delete functionality combined. I tried the code and it works great, but still gives me the same "missing value" error. Could it just be something with my machine? I wouldn't think so, but you never know...



[ Reply to This | # ]
Batch append data to the Notes field on Address Book cards
Authored by: tedw on May 23, '10 08:54:13PM

as I said, the 'missing value' comes from the 'save' line. in Address Book, the 'save' command returns no value (i.e., it gives 'missing value'), and since it's the last active line in the script that's what the script returns when you run it. don't worry about it. if it really bugs you, add the line "return" at the end of the script, and you'll get a different value.



[ Reply to This | # ]