TextEdit and Lion: error "you don't have permission" when opening

The problem:
I get an error message when I create a text file in Applescript and then try to tell TextEdit to open that file.
I have the feeling this happened after installing Lion.

The error message:

Here’s a simple example:

set the_file to (((path to desktop) as string) & "test.txt")

set fp to (open for access the_file with write permission)
write "Hello World!" to fp
close access fp

tell application "TextEdit" to open alias the_file

When you double-click the newly created file, it opens just fine in TextEdit.
Also, when I use Finder instead, it opens just fine (in TextEdit) from my Applescript.

tell application "Finder" to open the_file

Has anything changed?

BTW. when composing this MacScripter posting: Lion was not available yet in the System Info OS field

Maybe Applescript Editor doesn’t have permission? As far as I know, anything you do outside of “Tell” is done in Applescript Editor as if it says “Tell Applescript Editor”. I could be wrong, though…

Example:

display dialog (display dialog "You got it wrong!" buttons {"Quit", "Next"} default button 2 with icon alias ((path to me) & "Contents:Resources:thumbs_down.icns" as string))

This code looks inside Applescript Editor’s resources folder. However, if you save it as an app and open the app, it looks in that app’s resources folder.

The only exception is if it is just a normal script being opened in TextEdit as an application script via the script button in the top bar.

I’m not completely sure.

Thanks for reply.

Agreed, however in my example it is telling TextEdit.
And, TextEdit does open. But, with an untitled empty document and the error message.
And, the behavior changed as I did not see this issue before Lion.

Got it!

An alias is a pointer to a path. There is no file at the path of an alias.

And if there is no file, then TextEdit can hardly be blamed for not being able to open it.

Try opening a file instead:

set the_file to (((path to desktop) as string) & "test.txt")
tell application "TextEdit" to open file the_file

Have a good day!

Well done!
I did try earlier without the “alias” modifier, had not tried to use “file” instead.
Thanks a lot.