can anyone suggest a way to preview a text file without opening it
I found this somewhere but it gets a finder error:
tell application "Finder"
activate
if selection is equal to {} then
choose file with prompt "Choose a text file to preview"
set theFile to the result
else
set theFile to selection
end if
open for access file theFile
get eof of theFile
set fileLength to the result
if fileLength is greater than 255 then
read theFile for 255
else
read theFile
end if
set theData to the result
display dialog theData
close access theFile
end tell
think it might be one of Emmanuels, not sure
thanks,
Peter
tell application "Finder"
activate
if selection is equal to {} then
choose file with prompt "Choose a text file to preview"
set theFile to the result
else
set theFile to selection
end if
open for access (theFile as alias)
get eof of theFile
set fileLength to the result
if fileLength is greater than 255 then
read theFile for 255
else
read theFile
end if
set theData to the result
display dialog theData
close access theFile
end tell
Hope that helps.
i changed open for access file theFile to what is written above.
thanks
I still get the error:
Finder got an error: Can’t make {document file “Contacts Export.txt” of folder “WFA” of folder “Documents” of folder “p” of folder “Users” of startup disk} into a file.
tell application "Finder"
activate
if selection is equal to {} then
choose file with prompt "Choose a text file to preview"
set theFile to the result
else
set theFile to selection
end if
open for access theFile
get eof of theFile
set fileLength to the result
if fileLength is greater than 255 then
read theFile for 255
else
read theFile
end if
set theData to the result
display dialog theData
close access theFile
end tell