Re: Read Write Text File
Re: Read Write Text File
- Subject: Re: Read Write Text File
- From: hd <email@hidden>
- Date: Wed, 31 Mar 2010 16:29:44 +0100
Hi,
Words aren't text items, and AS treats the character - as a word delimiter.
Try this:
set bloop to "1 2 3 -4 5"
set AppleScript's text item delimiters to space
set bleep to text items of bloop
item 4 of bleep as integer
Result: -4
Watch out for this:
set bloop to "blue green greeny-blue"
set bleep to words of bloop
Result: {"blue", "green", "greeny", "blue"}
Better is:
set bloop to "blue green greeny-blue"
set AppleScript's text item delimiters to space
set bleep to text items of bloop
Result: {"blue", "green", "greeny-blue"}
But, as per a previous thread, watch out for double spaces in the original.
(Don't think you need to tell the Finder to do this?)
HTH
On 31 Mar 2010, at 14:51, Oakley Masten wrote:
I just saw the way my question showed up on the list.
Very sorry about the poor formatting.
That will be the last time that I write my inquiry using Word.
Here is a much better version.
Oakley
-----------------------------------
Read/Write Text Files
I want to read and write a preferences file for one of my scripts.
Text File-------- example
April 5, 2010
"Macintosh HD:Users:omasten:Desktop:Example.txt"
“Red” “Blue” “Green”
22 71 -18 -35 6
A date
A Path
3 colors
5 numbers [integers]
Easy enough.
Read the File---------
tell application "Finder"
activate
set theFile to Choose File
open for access theFile
set x to read theFile
close access theFile
set theData to Paragraph 1 of x
set theFilePath to Paragraph 2 of x
set theColors to Paragraph 3 of x
set theIntegers to Paragraph 4 of x
set theColorsList to words of theColors
display dialog item 3 of theColorsList
------> Green
set theIntegersList to words of theIntegers
display dialog item 3 of theIntegersList
------> 18 It should be -18
end tell
So what am I doing wrong here?
Is there a better way to read the lines?
Is there a better way to coerce the data into a list than using "Words of"
My head hurts!
Thanks
Oakley
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden