The following AppleScript both fails and succeeds at the open POSIX file destPath
.
The circumstances for success and failure are a little quirky.
It fails if Contacts
is closed prior to script activation. All other steps run successfully (and, in fact the delay
commands are not necessary. They merely demonstrate that timing isn't the cause of the error)
Error is: No cards added / No importable cards were found
, which would seem to suggest a corrupt vCards.vcf
file.
But the same script works just fine under the following conditions.
- Contacts is already launched prior to execution
- A manual import of the vCards.vcf file is executed prior to running the script.
If those two conditions are met, the script runs successfully repeatedly, as long as the app remains open.
tell application "Contacts"
activate
delay 3
delete people
save
delay 3
set destPath to "/path/to/vCards.vcf"
open POSIX file destPath
save
end tell