|
|
#1 |
|
Registered User
Join Date: Mar 2008
Posts: 2
|
read a file in an applescript.
Hi folks..
I'm trying to read a file in an applescript. I've tried a number of different syntax options. The most simple is: read theTextFile I get the following error: Expected end of line, etc. but found identifier. But this is the most basic syntax I've found. Any ideas? |
|
|
|
|
|
#2 |
|
League Commissioner
Join Date: Jan 2005
Posts: 8,475
|
Try it this way:
Code:
tell application "TextEdit" set x to posix file "/path/to/theTextFile.txt" as alias open x set file_text to text of document 1 end tell |
|
|
|
|
|
#3 |
|
MVP
Join Date: Apr 2004
Location: Hello London Calling
Posts: 1,787
|
I Thing the OP wants to read the file, rather than open it.
Code:
set x to posix file "/path/to/theTextFile.txt" as alias read x Code:
read alias "Macintosh HD:path:to:theTextFile.txt"
__________________
MH. |
|
|
|
|
|
#4 |
|
Registered User
Join Date: Mar 2008
Posts: 2
|
no good
No good.
Same thing. Won’t compile. Says: Expected end of line, etc. but found class name. And highlights whatever follows "read" ugh... weird. |
|
|
|
|
|
#5 |
|
League Commissioner
Join Date: Jan 2005
Posts: 8,475
|
Is your "read x" line inside a tell?
|
|
|
|
|
|
#6 |
|
Hall of Famer
Join Date: Apr 2007
Posts: 4,262
|
Code:
set fp to open for access <the filepath> set theFileContents to read fp close access fp
__________________
Philosophy is a battle against the bewitchment of our intelligence by means of language. -LW- |
|
|
|
|
|
#7 |
|
MVP
Join Date: Apr 2004
Location: Hello London Calling
Posts: 1,787
|
I Think cwtnospam is right the error is most likely in the rest of the script.
Can you let use see all the script as you are doing it. Tw, the open for access is for writing to the file AFAIK, and is not needed to just read a file. But not really knowing what the OP wants to really do who knows if they will need it?
__________________
MH. |
|
|
|
|
|
#8 | |||||||||||||||||||||||
|
Hall of Famer
Join Date: Apr 2007
Posts: 4,262
|
actually, open for access is for either reading or writing (read the standard additions scripting dictionary). my only other thought, though, is that maybe he's not quoting the or parenthesizing the file name correctly?
__________________
Philosophy is a battle against the bewitchment of our intelligence by means of language. -LW- |
|||||||||||||||||||||||
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|