The choose file and choose folder commands both have a problem with users attempting to select a folder using the search box that Apple provides in the file/folder dialog.
If you try this:
set afolder to choose folder --use the search box and select a folder that it finds return afolder
Script Editor’s event log will show:
tell current application choose folder "The variable afolder is not defined."
In similar fashion, if you use choose file and search for a file:
set afile to choose file --use search box and select a file return afile
then select it, Script Editor’s event log will show:
tell current application choose file "User canceled."
It’s unclear at what point these bugs were introduced, but they do appear as recently as OS X 10.4.11. Apparently both these errors are fixed in Leopard’s Applescript 2.0.