Tuesday, July 14, 2020

#1 2002-12-11 12:25:28 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

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?


One mans trash is another mans treasure


Filed under: Finder

Offline

 

#2 2002-12-11 05:52:31 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: 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:

Applescript:

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:

Applescript:

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


One mans trash is another mans treasure


Filed under: Finder

Offline

 

#3 2002-12-11 02:27:30 pm

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: Read file command in standard additions

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


One mans trash is another mans treasure

Offline

 

#4 2002-12-11 02:33:02 pm

T.J. Mahaffey
Administrator
From:: Arkansas, USA
Registered: 2002-11-20
Posts: 238
Website

Re: Read file command in standard additions

We happen to maintain an excellent list of such books.

http://macscripter.net/books.html


T.J.
tj@tjmahaffey.com

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)