Automator

Discussion in 'macOS' started by PowermacG5, Aug 30, 2007.

  1. PowermacG5 macrumors regular

    PowermacG5

    Joined:
    Jul 24, 2003
    Location:
    Grand Rapids, MI
    #1
    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
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    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.
     
  3. PowermacG5 thread starter macrumors regular

    PowermacG5

    Joined:
    Jul 24, 2003
    Location:
    Grand Rapids, MI
    #3
    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
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    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.
     
  5. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #5
    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.
     

Share This Page