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.
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.