Automator

PowermacG5

macrumors regular
Original poster
Jul 24, 2003
226
1
Grand Rapids, MI
So I export my yahoo contacts and i got this in my notes section (See below text). Is there a way to find address book contacts and delete the notes section. I have 1000 contact so It would be a pain to do it manualy. I have got as far as finding contact which contain "SOURCE: Yahoo" (in automator) and now cant figure out what to do next to actualy clear notes section.

SOURCE: Yahoo! AddressBook (http://address.yahoo.com)
CATEGORIES: All
X-CAT-IDS: 63
X-CID: 40
X-CREATED: 1127950899
X-MODIFIED: 1127951204
X-PRIMARY-PHONE: 0
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,842
7
USA
Applescript solution

Just so it's clear, what you want is to delete all lines in the file that begin with the "Source: ...", which is for notes?

I'm not very good with Automator, but I know this is possible with Applescript. Open "Script Editor" and copy and paste the following into it,

Code:
set clip to the clipboard as text
set numLines to the (number of paragraphs in clip) - 1

-- Change the delimiter to a space
set d to AppleScript's text item delimiters
set AppleScript's text item delimiters to {(ASCII character 13)}

set con to "" -- the end result
set x to 1 -- my loop counter

repeat numLines times
	if text 1 thru 7 of text item x of clip is not equal to "SOURCE:" then
		set con to con & text item x of clip & (ASCII character 13)
	end if
	set x to x + 1 -- increment
end repeat

set AppleScript's text item delimiters to d -- Reset the delimiter

set the clipboard to con as string
Save the file somewhere. Then select all of the text from your exported contacts file to the clipboard. Then, click the "Run" button in the script editor. Hopefully no errors. Then paste into a new text document in whatever text editor you like. If all went well you'll have everything except lines that begin with "Source:". There's a chance it won't work though due to line endings, but give it a try anyways and let me know if it works for you.
 

PowermacG5

macrumors regular
Original poster
Jul 24, 2003
226
1
Grand Rapids, MI
Well not really. I want to remove source: and all the rest
of the text which is slightly diff contact to contact.

CATEGORIES: All
X-CAT-IDS: 63
X-CID: 40
X-CREATED: 1127950899
X-MODIFIED: 1127951204
X-PRIMARY-PHONE: 0
__________________

numbers change. The notes field in address book has the giberish
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,842
7
USA
Well not really. I want to remove source: and all the rest
of the text which is slightly diff contact to contact.

CATEGORIES: All
X-CAT-IDS: 63
X-CID: 40
X-CREATED: 1127950899
X-MODIFIED: 1127951204
X-PRIMARY-PHONE: 0
__________________

numbers change. The notes field in address book has the giberish
Well if they all start with Source, then this'll work, it won't matter what text follows that. You can modify the script to handle each type of line that you don't want included. If you have trouble doing that, just ask.
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,842
7
USA
OK, I worked on one that handles all of the lines that you mention,

Code:
set clip to the clipboard as text
set numLines to the (number of paragraphs in clip) - 1

-- Change the delimiter to a space
set d to AppleScript's text item delimiters
set AppleScript's text item delimiters to {(ASCII character 13)}

set con to "" -- the end result
set x to 1 -- my loop counter

repeat numLines times
	if text item x of clip is equal to "" then
		set con to con & (ASCII character 13)
		
	else if text 1 thru 5 of text item x of clip is not equal to "SOURC" and text 1 thru 5 of text item x of clip is not equal to "CATEG" and text 1 thru 5 of text item x of clip is not equal to "X-CAT" and text 1 thru 5 of text item x of clip is not equal to "X-CID" and text 1 thru 5 of text item x of clip is not equal to "X-CRE" and text 1 thru 5 of text item x of clip is not equal to "X-MOD" and text 1 thru 5 of text item x of clip is not equal to "X-PRI" then
		set con to con & text item x of clip & (ASCII character 13)
	end if
	set x to x + 1 -- increment
end repeat

set AppleScript's text item delimiters to d -- Reset the delimiter

set the clipboard to con as string
Same as before, put this in script editor, copy your text from the file to clipboard, run the script, paste into new document and see if it works as expected. Good luck.