Reading data from a file

Hello,

Running Eggplant Purple here.

Can someone tell me where I am going wrong.

Consider this, in code if I do:


put (Uname:"user",Pwd:"password") into UsrDtls
put UsrDtls.Pwd
put UsrDtls.Uname

The script runs fine, in the debugger I see the correct values for UsrDtls.Pwd and UsrDtls.Uname.

Rather than have that information in the script though I want to read it from a file.

So in /Users/myuser/Documents/sometext.txt I have a line like this:

(Uname:“user”,Pwd:“password”)

My script is now like this:

put file "/Users/myuser/Documents/sometext.txt" into UsrDtls
put UsrDtls.Pwd
put UsrDtls.Uname

When I run it I get the following error:

Selection Failed 0:00:00 STUnknownMessage ERROR: No Such Function:‘pwd’

What am I doing wrong?

I say, the answer was in the Help all along :wink: well I never…

I needed to turn the contents of my text file into a property list first, which I did as follows:

put file "/User/myuser/Documents/sometext.txt" as a property list into UsrDtls

Then it worked clart.

:smiley:

That’s exactly right. When you read a file, it comes in as text. Specifying “as a property list” or calling the value() function on the text will convert it back to structured data.

put value(file “/Some/Path/To/SomeData.stplist”).Pwd