"with replacing" question
I found a cool script online to export Address Book entries as a batch of individual vcards. (The link to it is here:
http://scriptbuilders.net/files/exportaddressbookasvcards1.0.html)
I want to automate this, so I'd like to have it replace outdated vcards in the destination directory with their changed versions. My understanding is that the "with replacing" command will do this. But I added it, and when I changed someone's phone number in a vcard, the updated vcard didn't have the new phone number.
Below are the original script and my tweaked version with "with replacing" added in what I thought was the right location. Any suggestions on how to make this work would be very appreciated. Thanks.
-------original script below-------- ("xxxxx" hides actual username)
tell application "Address Book"
set PathName to "Users:xxxxx:Current:ABBackup:" -- insert your folder path here
--
set npersons to count of people
repeat with i from 1 to npersons
set vcardinfo to (vcard of person i) as text
set personName to (name of person i) as text
set target_file to PathName & personName & ".vcf" as text
try
set the open targetfile to ¬
open for access file target_file with write permission
set eof of the open targetfile to 0
write vcardinfo to the open targetfile starting at eof
close access the open targetfile
on error theErrMsg number theErrNumber
return theErrNumber
end try
end repeat
end tell
------my adjusted script with "with replacing" added to the line with "write vcard info"----------
tell application "Address Book"
set PathName to "Users:xxxxxx:Current:ABBackup:" -- insert your folder path here
--
set npersons to count of people
repeat with i from 1 to npersons
set vcardinfo to (vcard of person i) as text
set personName to (name of person i) as text
set target_file to PathName & personName & ".vcf" as text
try
set the open targetfile to ¬
open for access file target_file with write permission
set eof of the open targetfile to 0
write vcardinfo to the open targetfile starting at eof with replacing
close access the open targetfile
on error theErrMsg number theErrNumber
return theErrNumber
end try
end repeat
end tell
MacBook Pro 15"/2.16Ghz/2GB RAM Mac OS X (10.4.9)
I want to automate this, so I'd like to have it replace outdated vcards in the destination directory with their changed versions. My understanding is that the "with replacing" command will do this. But I added it, and when I changed someone's phone number in a vcard, the updated vcard didn't have the new phone number.
Below are the original script and my tweaked version with "with replacing" added in what I thought was the right location. Any suggestions on how to make this work would be very appreciated. Thanks.
-------original script below-------- ("xxxxx" hides actual username)
tell application "Address Book"
set PathName to "Users:xxxxx:Current:ABBackup:" -- insert your folder path here
--
set npersons to count of people
repeat with i from 1 to npersons
set vcardinfo to (vcard of person i) as text
set personName to (name of person i) as text
set target_file to PathName & personName & ".vcf" as text
try
set the open targetfile to ¬
open for access file target_file with write permission
set eof of the open targetfile to 0
write vcardinfo to the open targetfile starting at eof
close access the open targetfile
on error theErrMsg number theErrNumber
return theErrNumber
end try
end repeat
end tell
------my adjusted script with "with replacing" added to the line with "write vcard info"----------
tell application "Address Book"
set PathName to "Users:xxxxxx:Current:ABBackup:" -- insert your folder path here
--
set npersons to count of people
repeat with i from 1 to npersons
set vcardinfo to (vcard of person i) as text
set personName to (name of person i) as text
set target_file to PathName & personName & ".vcf" as text
try
set the open targetfile to ¬
open for access file target_file with write permission
set eof of the open targetfile to 0
write vcardinfo to the open targetfile starting at eof with replacing
close access the open targetfile
on error theErrMsg number theErrNumber
return theErrNumber
end try
end repeat
end tell
MacBook Pro 15"/2.16Ghz/2GB RAM Mac OS X (10.4.9)