![]() |
Address Book - Find and Replace?
Is there a Utility, Add-on, AppleScript, etc, that can do a Find and Replace within the OS X Address Book.?
Seems like such an obvious oversight. I tried editing the AddressBook.data file in Text Edit -- it's a good thing I did a backup first. That made a mess of things. |
I'm curious what your need is for a find & replace.
Most people have a collection of unrelated names & addresses, so find & replace isn't something that would be useful very often. |
To be specific in this instance, my data came from the old Palm Desktop which inserted a tag [Comments] into hundreds of entries, which now appears in the Notes field. There are tags that were generated by other programs that I am no longer using. This is not only a nuisance, but is taking up unnecessary space on my Palm.
I also take notes using certain terms that I now, and might in the future, want to change globally. One could certainly come up with other uses. I agree, it would be an occasional use item. But when needed, it is of critical, instrumental importance. |
1. Select all of the entries in your Address Book and drag them to your desktop. You'll get a single v-card with all of the data.
2. Open that v-card file in a text editor and make the replacements. 3. Backup your current address book (File>Backup Address Book). 4. Delete all of your address book entries. 5. Add the edited v-card back into address book (drag and drop or Import). Chris |
I could make the changes one by one in Address Book. Why should I go through all of that trouble?
|
You could perhaps write an AppleScript to do the search & replace operation.
|
Hello? That is what my post stated I am lookng for.
|
Quote:
Here's the procedure: 1) Google for something like: AppleScript "Address Book" 2) Look at all the results to see if anything might meet your needs. 3) If nothing turns up, learn AppleScript and write your own script. |
Thank you for that most basic info. I am not an idiot.
I did not thnk this was a personal request to you, but rather the greater audience of this forum. i have done so already, and posted here hoping to find a more learned and helpful answer. |
Are you not paying attention? I told you how to do it with just a word processor.
|
Quote:
However, I missed the part about it being ONE vcard, not multiples. I am concerned I will have to recheck every company as such, but I can do a backup frist and give it a try. Thank you. |
By the way, if chabig's solution turns out to be unsuitable for some reason and you end up having to write an AppleScript, here's one that I found via a quick google. It isn't anywhere close to what you want but might serve to give you an idea of how to write your own:
http://www.macosxhints.com/article.p...60420224740119 Note that one of the key things you will need to look at is which fields you wish to modify. |
Quote:
Chris |
It's odd hayne found a applescript so easly with google and Lambda Enterpris did not?
Anyway Hayne's find is actually very close to what you need. It just needed a couple of small changes. Code:
tell application "Address Book" |
Quote:
|
It's amazing how some will offer help, with p*ßs and vinegar attached. Really makes me appreciate their efforts.
BTW - Test your script before posting with such attitude. It doesn't work. End of topic, before I say something I'll regret. GROW UP, FOLKS. Karma. |
Quote:
:) |
Quote:
Saying "it doesn't work" is not too useful. |
hayne, you are the one who was being helpful. My apologies for not saying so. I was replying to Mr. Hunte who posted his script with a backhanded insult.
Can we PLEASE try and be civil here? The error I am receiving is: "The variable nfirst is not defined." |
Quote:
|
Quote:
Secondly Haynes suggestion of using google is good advice, which although your first post ask's for a applescript does not indicate you have done this. or tried to use anything you have found. Since you did do a search I find it odd you did not find anything helpful. As to the effort and the vinegar. I think it is a fair question to ask when you are asking for our effort. |
The script worked. Much thanks to all. I just wish we could have been nicer to each other.
At the end of the day...success. |
Find & replace.. with another string
Quote:
I finally found the right forum it seems. I have exactly the same problems of migration from Palm Desktop to Address Book as LambdaEnt and I am totally illiterate in Applescript. I would like to add my user comments on previous posts and specific requests. 1- Thanks to Mark for posting a script that works to help us. Unfortunatelly it falls short of answering the full issue (at least on my side), which is to find AND replace a string (with another string, as opposed to just finding and removing). Could somebody edit the script so as to prompt the user for a replacement string? The migration frpm PDtop to AB by Vcards leaves not only comments in my case with X |
For some reasons my previous post got shortened. Here is the rest.
I found that a gentleman named Alan Harper wrote a script to remove a any string from the AB's Note field: -- -- This script was written by Alan Harper. -- Questions can be directed to alan@alanharper.com -- Feel free to modify the script, but if you do, please remove my contact information above -- -- This script purports to remove a string from the "note" field in AddressBook -- You need to install MacPackToolbox <http://osaxen.com/files/macpacktoolbox1.4.html> first -- set newline to " " tell application "Address Book" set thePeople to selection set theCount to count of thePeople if theCount > 0 then set theDialogReply to display dialog ¬ "What string to remove from selected addresses?" default answer "" set theString to text returned of theDialogReply repeat with ctr from 1 to theCount set theId to id of item ctr of thePeople set theNote to note of item ctr of thePeople if theNote is missing value then set theNote to "" set oldNote to theNote set theNote to MP Replace theString using "" in string theNote repeat while length of theNote > 1 and (item 1 of theNote is " " or item 1 of theNote is return or item 1 of theNote is newline) set theNote to items 2 thru -1 of theNote as text end repeat repeat while length of theNote > 1 and (last item of theNote is " " or last item of theNote is return or last item of theNote is newline) set theNote to items 1 thru -2 of theNote as text end repeat if (theNote ? oldNote) then set note of (person id theId) to theNote end if end repeat end if end tell == 2- The other method through Vcard works although for some reasons I sometimes manage only a portion of the edited Vcards to import back into AB, which is something I have seen happening also between The Palm DT and AB. |
Try this.
Its less dangerous than the older script, as it only replaces whole words. (As far as my tests go - SO back up first) Example. if you want to remove or replace the word book, it will not touch words like booked, books, bookish where as the old one did. A side affect of the way I did this is in AddressBook, when you stop typing a line the last word will not be matched unless I add a space after it. so you may get an extra space after. I could add a part to remove all double white spaces (I think) but I do not really see the point. And it may remove ones that are there by intent. Code:
tell application "Address Book" |
Thanks Mark, that's very helpful.
I am testing your script right now. As I have 7000+ contacts, I wonder if you would be able to tweak it so as to have it only do the search and replace on either a Group or the records a selectedt the time; this could be useful as I transfer/add records from the Palm desktop to the Address Book in several steps. |
I am not sure of how to get the selected group ( or can not remember)
Some entries have more than on group. So they actually have more than one group name, therefore `I can not get the group of selection.. So it is easier to get all group names and you choose from that. Here. Code:
set AbGroups to {} |
How would I modify this script to search and replace data in the names field as well?
set AbGroups to {} tell application "Address Book" try set AbGroups to name of every group activate choose from list AbGroups set theGroup to item 1 of result display dialog "Enter the text String you are looking for in :Notes" default answer "" buttons {"Replace", "Remove", "Cancel"} default button 1 copy the result as list to {text_returned, button_pressed} set the_text to (people of group theGroup whose note contains text_returned) set DoNotMatch to "[^aA-zZ]" -- for later if the button_pressed is "Remove" then repeat with the_card in the_text set notes to my removeText(note of the_card, text_returned, DoNotMatch) set note of the_card to notes end repeat else if the button_pressed is "Replace" then display dialog "Enter the text to replace :" & text_returned default answer "" buttons {"Replace", "Cancel"} default button 1 copy the result as list to {replace_text, O_botton} repeat with the_card in the_text set notes to my replaceText(note of the_card, text_returned, replace_text, DoNotMatch) set note of the_card to notes end repeat end if save addressbook end try end tell on removeText(completeTxt, removeTxt, DoNotMatch) set removeTxt to do shell script "echo " & quoted form of removeTxt & "|sed -e 's/\\ /\\\\ /g' " as string set completeTxt to completeTxt & " " -- adds a space to words on the end of the line or they will not be matched set completeTxt to do shell script "echo " & quoted form of completeTxt & "|sed -e 's/" & quoted form of removeTxt & DoNotMatch & "/\\ /g'" return completeTxt end removeText on replaceText(completeTxt, replacedTxt, replace_text, DoNotMatch) set replacedTxt to do shell script "echo " & quoted form of replacedTxt & "|sed -e 's/\\ /\\\\ /g' " as string set replace_text to do shell script "echo " & quoted form of replace_text & "|sed -e 's/\\ /\\\\ /g' " as string set completeTxt to completeTxt & " " -- adds a space to words on the end of the line or they will not be matched set completeTxt to do shell script "echo " & quoted form of completeTxt & "|sed -e 's/" & quoted form of replacedTxt & DoNotMatch & "/" & quoted form of replace_text & "\\ /g'" return completeTxt end replaceText |
| All times are GMT -5. The time now is 01:43 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.