Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AppleScript error - The variable people is not defined.

Running 10.9.4 on an iMac


Some time ago I started using the following AppleScript:


tell application "Contacts"

set the clipboard to (vcard of people) as text

do shell script "pbpaste > Contacts.vcf"

set the clipboard to ""

end tell


This worked fine until yesterday when it failed with the following error:


export.scpt:59:65: execution error: The variable people is not defined. (-2753)


I tried a number of times and even rebooted but it keeps giving the error (in fact I remember it started giving this error in March but I didn't get to the bottom of it and a couple of weeks later it started working again so I forgot about it). I know very little about AppleScript and am hoping that someone can suggest a fix.


Thanks

Posted on Jul 5, 2014 4:07 PM

Reply
15 replies

Jul 6, 2014 3:20 PM in response to Frank Caggiano

I have been testing it by running "osascript export.scpt" and didn't even know that it was compiled. I am now doing it by running "open export.scpt" which opens it in AppleScript Editor. In there when I click "Compile" nothing happens, and it can't be saved ("changes will not be saved until the problem is solved"). If I click on "Run" it says:


error "The variable people is not defined." number -2753 from "people"

Jul 6, 2014 3:50 PM in response to ianji

Open the script in the Applescript editor and run it. See if the vertical bars are added.


I ask because for some reason after I copied your code into the Applescript editor it put the bars around the two names which causes Applescript to interpret the names as variables not as arguments to Contacts. This caused the error. When I removed the bars and re-ran it it ran Ok, the bars weren't added back in.


No idea why I saw hat I saw but am curious to see if you are getting the same result.


Just tied it again and got the same result


set the clipboard to (|vcard| of |people|) as text


error "The variable people is not defined." number -2753 from "people"


when I removed the bars and run it it runs OK.


Note: If I add activate after the tell statement before compiling it, it compiles OK. Is it possible that before you started getting this problem you had Contacts open before running the script and now you do not?

Jul 6, 2014 4:39 PM in response to Frank Caggiano

I have tried all sorts of variations but can't get the vertical bars to appear. However, you hit the nail on the head with the bit about Contacts being open. If Contacts is open then the script runs fine, if not it gives the error. This is strange because I am finding it hard to believe that I always had Contacts open when running the script up until I first got the error.


I tried adding "activate" but when I then ran it without Contacts being open I got:


error "An error of type -10661 has occurred." number -10661


But at least I can get it to run now simply by making sure Contacts is open.

Jul 7, 2014 4:09 AM in response to VikingOSX

As Frank suggested, the error only occurred when I tried to run the script when the Contacts application was not open. Of course it makes sense, but the error message could have been more informative:-)


Trying your script again now with Contacts open it does indeed run without error and writes a file called Contacts.vcf to my Desktop. Unfortunately it is an empty file. I even tried selecting all contacts in Contacts first but it still creates an empty file, whereas my original script (which I found somewhere) does what I want, provided Contacts is already open.


You will see in my most recent response to Frank that I tried adding "activate" to open Contacts if it is not already open, but that just gave a different error.


Frank also said that the AppleScript editor was adding vertical bars around "vcard" and "people" but that is not happening for me so something strange is going on.

Jul 7, 2014 6:14 AM in response to ianji

Something is strange with this.


As a rule the tell application statement should be sufficient for Applescript to realize the terms in the tell block are from that application without actually activating the application (either by the active command or by having the application open before the script runs)


And the problem is not consistent for me. Just tried it again (selected your code, made an Applescript from it and this time it worked ok)


With I had more, glad you were able to work around the problem, but it definitely isn;t fixed. Can you think of anything that changed on your system at the time the problem first appeared?

Jul 7, 2014 8:42 AM in response to Frank Caggiano

I can't think of anything that changed. As I said, I first noticed the problem in March, but I only run the script about once a month and it has worked since then, until a couple of days ago when I got the error again. So all I really know is that I have to have Contacts open before I run the script, but I don't know if that has always been the case or whether that changed with an OS upgrade at some point. If I get any more clues I will try to remember to post here again.

Jul 7, 2014 11:15 AM in response to ianji

I had this problem when I upgraded to 10.9.4. Rebuilding the launch services database fixed it.


-- script downloaded from macscripter.net


display dialog "The Finder must quit and will relaunch after the Launch Services rebuild is complete. The rebuild may take several minutes, during which time you should refrain from using any other apps." buttons {"Cancel", "Rebuild LS Database"} default button 2 with icon caution

ignoring application responses

tell application "Finder"


delay 2


quit

end tell

end ignoring

delay 5

tell application "System Events" to set running_applications_ to get name of every application process

if running_applications_ contains "Finder" then do shell script "killall Finder"

do shell script "/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.fr amework/Support/lsregister -kill -r -domain local -domain system -domain user"

tell application "Finder"


delay 2


activate

end tell

tell me to activate

display dialog "The Launch Services rebuild is now complete." buttons {"OK"} default button 1 with icon note

Jul 7, 2014 1:21 PM in response to twtwtw

No we are getting somewhere!


In terminal I went into the directory containing the lsregister command and typed "./lsregister -kill"


That was all that was needed, now my script works whether or not Contacts is running (if it isn't then it gets opened automagically)


Had I not already indicated that Frank's reply solved my question (which it did in a way) I would have given you the credit. Making sure that Contacts was already open was an acceptable workaround but clearly the launch services database needed fixing.

AppleScript error - The variable people is not defined.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.