• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
why is applescript so slow???
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

why is applescript so slow???


  • Subject: why is applescript so slow???
  • From: "halloolli" <email@hidden>
  • Date: Tue, 30 Nov 2004 15:27:08 +1100

hi there

i have figured out a little script which duplicates all cards of the addressbook and assigns these duplicates to a special group (thanks heaps to Paul Berkowitz for the copy person part!).

in script editor this takes for 200 cards a couple of minutes! on a g4 imac!!! this can't be right, so what do i do wrong, or is applescript really that slow??? i have attached the source code of my script.

for the loop lists i tried to use references instead of the lists themself, but it doesn't make a big difference. are there other ways to get a usable performance?

cheers, olli

ps: i go through the whole procedure of duplicating the data in order to tweak some properties of the cards for syncing with my phone (eg. my phone doesn't like companies with empty name fields), but these tweaks should only happen for the phone hence i have to _copy_ everything upfront.


*** cut *** script: copy all cards of address book and assign them to special group *** cut ***


-- main
set mobileName to "_mobile"
set mobileGroup to my recreate_group(mobileName)

tell application "Address Book"
   set refPeopleList to a reference to name of every person
   repeat with pName in refPeopleList
       set p to (first person whose name is pName)
       if (name of every group of p) does not contain mobileName then
           if not my dont_copy_this(p) then
               add my copy_person(p) to mobileGroup
               save addressbook
           end if
       end if
   end repeat
end tell

-- delete group with its cards and recreate it
on recreate_group(gName)
   tell application "Address Book"
       if ((name of every group) contains gName) then
           set gFound to (the first group whose name is gName)
           set delList to {}
           set allPeople to every person
           script localScript
               property refAllPeople : allPeople
           end script
           repeat with p in localScript's refAllPeople
               set pGroupNames to name of every group of p
               if pGroupNames contains (name of gFound) then
                   set end of delList to p
               end if
           end repeat

set msg to "delete group " & (name of gFound as string) & " and its " & (count of delList) & " (of " & (count of every person) & ") cards?"
display dialog msg


           if button returned of result is "OK" then
               repeat with p in delList
                   delete p
               end repeat
               delete gFound
           end if
       end if
       return make new group with properties {name:gName}
   end tell
end recreate_group

-- check wether to copy this person over
on dont_copy_this(pers)
   tell application "Address Book"
       set w to words of (note of pers as string)
       return w contains "nosync"
   end tell
end dont_copy_this

-- the copy stuff for one person
on copy_person(p)
tell application "Address Book"
tell p
set p_props to its properties
set allAddresses to properties of every address
set allPhones to properties of every phone
set alleMails to properties of every email
set allRelatedPeople to properties of every related name
set allCustomDates to properties of every custom date
set {allAIMHandles, allMSNHandles, allICQHandles, allJabberHandles, allYahooHandles} to {properties of every AIM Handle, properties of every MSN handle, properties of every ICQ handle, properties of every Jabber handle, properties of every Yahoo handle}
set allGroups to every group
end tell



tell p_props
set {maidenName, middleName, phoneticLastName, ifOrganization, theDepartment, thesuffix, theNote, lastName, phoneticFirstName, theCompany, birthDate, theTitle, jobTitle, theNickname, phoneticMiddleName, theImage, firstName, homePage} to {maiden name, middle name, phonetic last name, organization, department, suffix, note, last name, phonetic first name, company, birth date, title, job title, nickname, phonetic middle name, image, first name, home page}


           (* here i want to do the adjustments for my phone
              like swaping company to name, etc *)

set newProps to {maiden name:maidenName, middle name:middleName, phonetic last name:phoneticLastName, organization:ifOrganization, department:theDepartment, suffix:thesuffix, note:theNote, last name:lastName, phonetic first name:phoneticFirstName, company:theCompany, birth date:birthDate, title:theTitle, job title:jobTitle, nickname:theNickname, phonetic middle name:phoneticMiddleName, image:theImage, first name:firstName, home page:homePage}
end tell


set target_p to make new person at end of people with properties newProps

tell target_p
repeat with i from 1 to (count allAddresses)
set addressProps to item i of allAddresses
tell addressProps to set targetAddressProps to {label:label, street:street, city:city, state:state, zip:zip, country:country, country code:country code}
make new address at end of addresses with properties targetAddressProps
end repeat
repeat with i from 1 to (count allPhones)
set phoneProps to item i of allPhones
tell phoneProps to set targetPhoneProps to {label:label, value:value}
make new phone at end of phones with properties targetPhoneProps
end repeat
repeat with i from 1 to (count alleMails)
set emailProps to item i of alleMails
tell emailProps to set targetEmailProps to {label:label, value:value}
make new email at end of emails with properties targetEmailProps
end repeat
repeat with i from 1 to (count allRelatedPeople)
set relatedProps to item i of allRelatedPeople
tell relatedProps to set targetRelatedProps to {label:label, value:value}
make new related name at end of related names with properties targetRelatedProps
end repeat
repeat with i from 1 to (count allCustomDates)
set dateProps to item i of allCustomDates
tell dateProps to set targetDateProps to {label:label, value:value}
make new custom date at end of custom dates with properties targetDateProps
end repeat



repeat with i from 1 to (count allAIMHandles)
set aimProps to item i of allAIMHandles
tell aimProps to set targetAimProps to {label:label, value:value}
make new AIM Handle at end of AIM handles with properties targetAimProps
end repeat
repeat with i from 1 to (count allMSNHandles)
set msnProps to item i of allMSNHandles
tell msnProps to set targetMsnProps to {label:label, value:value}
make new MSN handle at end of MSN handles with properties targetMsnProps
end repeat
repeat with i from 1 to (count allICQHandles)
set icqProps to item i of allICQHandles
tell icqProps to set targetIcqProps to {label:label, value:value}
make new ICQ handle at end of ICQ handles with properties targetIcqProps
end repeat
repeat with i from 1 to (count allJabberHandles)
set jabberProps to item i of allJabberHandles
tell jabberProps to set targetjabberProps to {label:label, value:value}
make new Jabber handle at end of Jabber handles with properties targetjabberProps
end repeat
repeat with i from 1 to (count allYahooHandles)
set yahooProps to item i of allYahooHandles
tell yahooProps to set targetYahooProps to {label:label, value:value}
make new Yahoo handle at end of Yahoo handles with properties targetYahooProps
end repeat


       end tell

return target_p
end tell
end copy_person



_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: why is applescript so slow???
      • From: peter boardman <email@hidden>
    • Re: why is applescript so slow???
      • From: wayne melrose <email@hidden>
    • Re: why is applescript so slow???
      • From: Sander Tekelenburg <email@hidden>
  • Prev by Date: Re: Entourage Rules & AppleScript
  • Next by Date: Re: why is applescript so slow???
  • Previous by thread: Re: Entourage Rules & AppleScript
  • Next by thread: Re: why is applescript so slow???
  • Index(es):
    • Date
    • Thread