Any work around for choose file bug?

I’m a newbee so excuse me if I’m asking a dumb question.

When I use “choose file” to a get a file on the system, and I use the search feature in the dialog, I always get a “User canceled” error when a click on the “Choose” button.

Is there some secret to make this work right or is there an alternative method to accomplish the same thing?

Welcome. :slight_smile:

I don’t have that problem on my system… Would you post the code that you’re using for this?

This happens in both studio and script editor
When the dialog comes up I type .aiff in the search field then choose a file I know is in my iTunes directory.
I then get the User canceled error

I’m running 10.4.11 on MacBook Pro Duo, latest xcode for tiger

set f to choose file
on error msg
display dialog msg
end try

It also happens on my G4. Applescript version on both machines is 1.10.7

I cannot explain it other than to call it a bug, but I see the same thing on my system (10.4.11 on a G4).

For me, the key to reproducing the problem was to use the search function (something I had never actually done in that context). When I select a file from a search in the choose file dialog, it always generates a “User canceled.” (-128) error. When I just navigate to the file and select it without using the search (what I have always done), it works OK. I never even really noticed that search feature before. I guess not many other people use it either (or they found that it does not work, and they just learn to avoid it).

When using the search feature of the choose folder dialog, I see a different bug where it does not throw an error, but just returns no result. Odd.

Model: iBook G4 933
AppleScript: 1.10.7
Browser: Safari 3.0.4 (523.12)
Operating System: Mac OS X (10.4)

I don’t recall using it either.

Apparently both of these behaviors are fixed in AppleScript 2.0 (Mac OS X v10.5).

Tiger 10.4.11 on a PM G4 here, and yep, it dies for me also. Odd…

Model: 466mhz DA G4 tower (“Morpheus”) with 512mb
AppleScript: 1.10
Browser: Safari 3.0.4 (523.12)
Operating System: Mac OS X (10.4)

Not entirely satisfactory, I suppose, but here’s one possible work-round: :confused:

		set f to (choose file)
		exit repeat
	on error number -128
		-- If the 'User canceled." error occurs with any sub-version of AS 1.10,
		-- ask the user to take appropriate action. Otherwise, regenerate the error. 
		if ((system attribute "ascv") mod 4096 div 16 is 26) then
			display dialog "AppleScript " & (AppleScript's version as text) & "'s 'choose file' dialog has (or may have) a bug. If you clicked \"Cancel\", please do so again here. Otherwise NAVIGATE to the chosen file without using the dialog's \"Search\" function." buttons {"Try again.", "Cancel"} default button 2 cancel button 2 with icon note
			error number -128
		end if
	end try
end repeat

If the bug only affects AS 1.10.7, the version check can easily be modified to exclude the other 1.10.x versions.


It would eliminate the impact on the user of unpredictable and frustrating program behavior. Simply pointing out the problem in a read-me file would probably only help a small percentage of users.

I suppose one could go a step further and add a “do not show me this again” option to the warning dialog.

Then again, is this more work than it’s worth? It seems like very few people notice this option and fewer probably use it. Otherwise this would have been on the radar before now.

I discovered it because I’m writing a program that plays short sounds that you can choose. Being able to see what was on the system seemed convenient. I added the ability to drag and drop the file so they could use spotlight easily. It is a much better way to do it because you see where the file is located. In the choose file dialog, you can only tell if the file is in “Documents”, Home, or anywhere.

Yeah. But it’s still reasonable for a user to try to use the option, especially since it works in non-AppleScript contexts. Once you know there’s a bug in the system that could make your script look silly, you have to cope with it somehow ” even if (as in this case) you can only point the blame. :rolleyes:

A briefer approach would be to put a warning in the dialog’s prompt text. Once this had been noticed by the user, it would likely be less annoying than a follow-up dialog.

set cfPrompt to "Please choose a file."
if ((system attribute "ascv") mod 4096 div 16 is 26) then
	set cfPrompt to (cfPrompt as Unicode text) & " (DON'T USE THE \"SEARCH\" FEATURE FOR THIS OPERATION!)  " & «data utxt2B07»
end if
set f to (choose file with prompt cfPrompt)

Thanks for the advice.

I like the less obtrusive approach of putting the warning in the choose file dialog.