Applescript to read data from text file

Hello all, I am writing an Applescript to read a file and put that file's contents into a variable. However, when I use the applescript command "read", I get the error:

User uploaded file

The text file reads "4.65". I need to extract that number to show up in a dialog box. This is the code I have so far.


set milefile to ("Macintosh HD:Users:RyanSiebecker:Documents:Scripts:Source-Files:Running-Files:milefile.tx t")

set theFileContents to (readfilemilefile)


I am stuck and I cannot find any other way to do this.

As always, any help is appreciated.

Thanks, Ryan

MacBook Pro, OS X Mavericks (10.9.1)

Posted on Mar 30, 2014 11:04 AM

Reply
4 replies

Mar 30, 2014 11:37 AM in response to RyanSiebecker

Have you noticed that your file name's extension (".tx t") has a space in it? Though that mismatch would get a -43 Not Found error, not EOF.


Your code ( with and without the gapped extension) works here.


Maybe the path isn't perfect?


To make a perfect path easily, start with this:


set milefile to POSIX file ("") -- note the null string ("")


Then arrange your windows so that you can drag the icon representing your file from wherever it is in the Finder's world into your AppleScript Editor's window, and carefully drop it right between the ""s.


If you miss, don't worry. It'll be selected, so just Cut and then Paste it between the ""s. You'll get a perfect path, only with slashes instead of colons. The "POSIX file" specifier converts it to "colon notation", still perfectly.


--Gil

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript to read data from text file

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.