• 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
Working with text files in AppleScript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Working with text files in AppleScript


  • Subject: Working with text files in AppleScript
  • From: Taner Edis <email@hidden>
  • Date: Fri, 12 Sep 2003 16:35:05 -0500

Hi,

I'm new at AppleScript  I thought it'd be a good idea to learn some of
its basics after I got myself an OS X Mac. There's a question I
haven't been able to resolve by looking at the web and the book I have
on hand; perhaps someone here can point me in the right direction.

I thought I'd write a script to convert the html files authomatically
generated by iPhoto, to make them conform to my standard web pages
which have some style sheet stuff, and a standard footer at the bottom.
So I figured it'd be easy to just read in a text file, do a quick
search-and-replace, and rewrite the result out.

It seems, however, that I can't get past the first hurdle, of
successfully reading the contents of a text file into a string. How do
you do this? Here's a test script that I wrote, which always ends up
in the error part, displaying 'It didn't work," never getting to "text
read!". I'm sure I'm doing something wrong which is elementary...


set my_text to "" as text
set my_file to (((path to desktop folder) as text) & "Desktop.html")
my read_file(my_file, my_text)
display dialog my_text

on read_file(some_file, some_text)
try
set some_file to some_file as text
display dialog some_file
set the open_target_file to ,
open for access file some_file
display dialog open_target_file as text
read some_text from the open_target_file
display dialog "text read!"
close access the open_target_file
return true
on error
display dialog "It didn't work"
try
close access file some_file
end try
return false
end try
end read_file

Thanks for any help you can offer.

Taner Edis
http://www2.truman.edu/~edis/
_______________________________________________
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: Working with text files in AppleScript
      • From: Andrew Oliver <email@hidden>
References: 
 >Re: AppleScript dictionary (From: "Marc K. Myers" <email@hidden>)

  • Prev by Date: Re: AppleScript dictionary
  • Next by Date: Re: AppleScript dictionary
  • Previous by thread: Re: AppleScript dictionary
  • Next by thread: Re: Working with text files in AppleScript
  • Index(es):
    • Date
    • Thread