Way better. I was lazy twice: once when I didn't check for existence of the group, and also when I just picked a start date and not an end date.
I like using "set foundGroup to people whose creation date ..." instead of "every person whose". Had not seen that used before.
The nice thing about putting people into the group is they may not have names, or emails, or whatever, so you can't rely on "names of people whose" in your list.
Is there a way to eliminate the "repeat with i in foundGroup" loop? Add every item of foundGroup to group "tempgroup"? I haven't figured it out.
Finally, better have a "Save" in the script. Try it with and without out you'll like it better with.
Here's a shorter example (do it with Address Book open so you can see it happen):
tell application "Address Book" make new group at end with properties {name:"tempgroup"} save end tell
that works.
Take out the Save and it doesn't work. At least not here. Leaving out the Save has messed me up plenty of times with Address Book scripting.
c
On Jun 20, 2011, at 12:04 PM, Christopher Stone wrote: On Jun 20, 2011, at 00:33, Christian Boyce wrote: Or, create a group in Address Book and take all of those people that you find in Chris' script (below) and put them into that group. ______________________________________________________________________
Hey Christian,
That's certainly a more organic way of handling things. Let's see if we can improve on it just a smidgen.
-- Best Regards, Chris
set dateRangeStart to date "Tuesday, September 14, 2010 00:00:00" set dateRangeEnd to date "Wednesday, September 15, 2010 00:00:00"
tell application "Address Book" activate try if (group "tempgroup" exists) = false then set newGroup to make new group at end with properties {name:"tempgroup"} set foundGroup to people whose creation date > dateRangeStart and creation date < dateRangeEnd repeat with i in foundGroup add i to group "tempgroup" end repeat save set selected of group "tempgroup" to true else error "Group 'tempgroup' Already Exists!" end if on error errMsg number errNum set sep to "==============================" set e to sep & return & "Error: " & errMsg & return & sep & return ¬ & "Error Number: " & errNum & return & sep beep display dialog e end try end tell
--
Christian Boyce Christian Boyce and Associates Mac, iPhone, and iPad Consultants 310-452-3720
|