• 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: Read a text file ...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Read a text file ...


  • Subject: Re: Read a text file ...
  • From: Charles Heizer <email@hidden>
  • Date: Sat, 19 Apr 2003 11:12:13 -0700

Hi John,
This looks great, thanks a bunch.

I do have a question about the results, how do I map the items from the text file to my variables?

example...
set theHost to "myfirsthost.example.com"
set theUser to "user"
set thePass to "password"

Thanks again for the help.

- Charles


On Saturday, April 19, 2003, at 10:25 AM, John Delacour wrote:

At 9:32 am -0700 19/4/03, Charles Heizer wrote:

Hello,
I'm writing a small applescript to scp a couple of files to a list of hosts. I have crated a text file that has the info I need, it looks like this -

myfirsthost.example.com;user;password
host2.example.com;user;password

So the file is delimited by semicolons. So I've been reading the archives and I can't seem to figure out how to fill in the variables in my script with the contents of each line.



You probably want something like this:


writeFile() -- make the sample file see (**) below
set fU to "/tmp/host.txt" -- UNIX pathname of file
set f to POSIX file fU -- file specification
set sStuff to {} -- in this case a list of lists
set sSeparator to ";"
set text item delimiters to sSeparator
open for access f
repeat
try
set lLine to read f until return
if lLine contains sSeparator then
set end of sStuff to text items of lLine
end if
on error
exit repeat
end try
end repeat
close access f
set text item delimiters to ""
sStuff


(**)
on writeFile()
set fU to "/tmp/host.txt"
set f to POSIX file fU
set s to "
myfirsthost.example.com;user;password
host2.example.com;user;password
"
open for access f with write permission
set eof f to 0
write s to f
close access f
end writeFile
_______________________________________________
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.

  • Follow-Ups:
    • Re: Read a text file ...
      • From: John Delacour <email@hidden>
References: 
 >Re: Read a text file ... (From: John Delacour <email@hidden>)

  • Prev by Date: Re: Read a text file ...
  • Next by Date: Dropin'
  • Previous by thread: Re: Read a text file ...
  • Next by thread: Re: Read a text file ...
  • Index(es):
    • Date
    • Thread