Using the notes field in Address Book with Applescript

I’m trying to use the notes field to store information about my contacts so I can use this in a custom group mailer.

I’m trying to store a delimted value like:

Date:[current date] | Text text Text

The delimiter is “|”.

The other option would be to store data line by line like so:

Test 1
Test 2

Applescript doesn’t appear to be able to parse the string into fields (top example) so that I can enumerate through the list and get the item.

It doesn’t appear to get each line by line but gives the entire string: {“Test 1 Test 2”}

I’m new to Applescript. Am I doing something wrong?

Browser: Safari 533.19.4
Operating System: Mac OS X (10.6)

Hi, axwack. Welcome to MacScripter.

You haven’t posted your code, so it’s hard to say! Also, your two examples don’t match, so it’s impossible to tell what your input actually is and what you want to do with it.

AppleScript can, in fact parse, text into fields (“text items” in AppleScript parlance) like this:

set originalText to "Date:[current date] | Text text Text"

set astid to AppleScript's text item delimiters -- Store the current delimiter value.
set AppleScript's text item delimiters to " | " -- Set the delimiter to what you want to use.
set theFields to originalText's text items -- Get a list of the text items.
set AppleScript's text item delimiters to astid -- Restore the original delimiter.

return theFields --> {"Date:[current date]", "Text text Text"}

It can also separate text into individual paragraphs:

set originalText to "Test 1
Test 2"

set theParagraphs to paragraphs of originalText --> {"Test 1", "Test 2"}

If you want to put the fields of a " | "-delimited text onto separate lines, you can do this:

set originalText to "Date:[current date] | Text text Text"

set astid to AppleScript's text item delimiters -- Store the current delimiter value.
set AppleScript's text item delimiters to " | " -- Set the delimiter to what you want to use.
set theFields to originalText's text items -- Get a list of the text items.

set AppleScript's text item delimiters to linefeed -- Change the delimiter to a linefeed.
set newText to theFields as text -- Coerce the text items back together with this delimiter.
set AppleScript's text item delimiters to astid -- Restore the original delimiter.

return newText
(* -->
"Date:[current date]
Text text Text"
*)

Afterthought:

If your problem is that you want to get the note from a person in Address Book, this is the way:

tell application "Address Book"
	set theNote to note of person "Blah Blah"
end tell