• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Reading input from a delimited source file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reading input from a delimited source file


  • Subject: Re: Reading input from a delimited source file
  • From: "Marc K. Myers" <email@hidden>
  • Date: Thu, 9 Jan 2003 10:24:32 -0500

Date: Wed, 8 Jan 2003 13:10:58 -0600
Subject: Reading input from a delimited source file
From: Joseph Weaks <email@hidden>
To: AppleScript <email@hidden>

What am I doing wrong? I have a text file that has paragraph delimited
data. Basically, I want to read the content of the first paragraph, do
stuff with it, then repeat with each paragraph. Here's what I've been
trying:

-- Begin code snippet
Property sourceFile : "Source.txt"

set theSource to (open for access file ((path to desktop as string) &
sourceFile as string)

set AppleScript's text item delimiters to (ASCII character 13)
set sourceList to text items of theSource

repeat with x from 1 thru (length of sourceList)
set eachSource to item x of sourceList as string
-- do stuff with eachSource.
end repeat

close access theSource
-- End code

I'm getting a "Can't get every text item of ..." error.
Is there a better way to go about this? Some kind of
set eachSource to paragraph x of theSource?

Right now, each paragraph is only one word, so there's not a problem
loading the whole file into memory. I would like to also see a nice clean
handler that works if the source file is too long to load all at once.

It appears to me that what you're doing wrong is never reading the file. You open it, setting theSource to the file identifier. Then you attempt to parse the file identifier as if it were the file's contents. The file identifier is an integer value and wouldn't have any text items.

Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074

[01/09/03 10:23:07 AM]
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: OSX script to change/copy file icon ?
  • Next by Date: Re: Forcing 'tell app' to use carbon, rather than classic app/
  • Previous by thread: Re: Reading input from a delimited source file
  • Next by thread: Scripts as Service?
  • Index(es):
    • Date
    • Thread