Read file command in standard additions

I have written a script in OS9 and am trying to get part of it to work in OSX.

The script selects a text file and reads it to a variable.

tell application “Finder”
activate
set order to “secure_979491123.27578.txt”
select file order of folder “Macintosh HD:Documents:Secure Orders”
set orderdata to read selection
end tell

I get an error “Can’t make selection into a file”

I don’t get this error in OS 9. Anybody know what is going on here?

‘file “foo” of folder “bar”’ is a Finder object reference. Only Finder understands those, other apps and scripting additions don’t. Like most, the Standard Additions’ read command requires an alias.

OS 9 Finder was quietly converting the Finder object reference to an alias for you. OS X Finder isn’t so forgiving, so you’ll need to coerce it yourself:

set order to "secure_979491123.27578.txt"
tell application "Finder"
	set fAlias to (file order of folder "Macintosh HD:Documents:Secure Orders") as alias
end tell
set orderdata to read fAlias

(No need to mess around with ‘selection’, incidentally.)

If you’ve no particular cause to use Finder, this will do the same as the above:

set fold to "Macintosh HD:Documents:Secure Orders:"
set order to "secure_979491123.27578.txt"
set fAlias to alias (fold & order)
set orderdata to read fAlias

What’s best depends on what you’re doing.

HTH

Thanks for the help. can you recommend a book on these hidden nuances with applescript?

We happen to maintain an excellent list of such books.

http://macscripter.net/books.html