• 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 a file in an applescript.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reading a file in an applescript.


  • Subject: Re: reading a file in an applescript.
  • From: Doug Meade <email@hidden>
  • Date: Fri, 21 Mar 2008 15:58:38 -0400
  • Thread-topic: reading a file in an applescript.

Title: Re: reading a file in an applescript.
Thanks Mark.

The "theTextFile" was set to a mac path.
Like your example:
Macintosh HD:this:is:where:it:is:foo.txt"

Specifically :

   tell application "Finder"
        
          set theScriptPath to (container of application file (path to me) as Unicode text)
        
    end tell
    
    set theTextFile to (theScriptPath & replyTemplateName)
    
    set targetFile to theTextFile

    set readHandle to (open for access targetFile)
    set fileText to (read readHandle for (get eof readHandle))
    close access readHandle
    FileText


The last 4 lines are your code (thank you).
But I still get the “Expected end of line, etc. but found identifier.” error and the editor highlights readHandle

Do I need to do something special to “enable” file system functions?

Thanks a lot!
Doug



> From: "Mark J. Reed" <email@hidden>
> Date: Fri, 21 Mar 2008 15:44:57 -0400
> To: Doug Meade <email@hidden>
> Cc: <email@hidden>
> Subject: Re: reading a file in an applescript.
>
> On Fri, Mar 21, 2008 at 3:35 PM, Doug Meade <email@hidden> wrote:
>>
>>  Hi folks!
>>  New to applescript ...
>>  I'm trying to read a file in an applescript.
>>
>>  I've tried a number of different syntax options.
>>  The most simple is:
>>
>>  read theTextFile
>
> Welll, that won't work, first of all, but what is the value of
> "theTextFile"?  Are you setting it to a file name, an alias, the
> result of an open for access call, or what?
>
> Here's a model:
>
> set targetFile to (choose file with prompt "Pick a file")
> set readHandle to (open for access targetFile)
> set fileText to (read readHandle for (get eof readHandle))
> close access readHandle
> fileText
>
> If you have a filename you want to read, instead of prompting the user
> for the file interactively, then you should
>
> set targetFile to file "Macintosh HD:this:is:where:it:is:foo.txt"
>
> or
>
> set targetFile to POSIX file "/this/is/where/it/is/foo.txt"
>
> the rest is the same.
> --
> Mark J. Reed <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

  • Follow-Ups:
    • Re: reading a file in an applescript.
      • From: Shane Stanley <email@hidden>
    • Re: reading a file in an applescript.
      • From: "Mark J. Reed" <email@hidden>
    • Re: reading a file in an applescript.
      • From: Michelle Steiner <email@hidden>
References: 
 >Re: reading a file in an applescript. (From: "Mark J. Reed" <email@hidden>)

  • Prev by Date: Re: Number Format Problem
  • Next by Date: Re: Number Format Problem
  • Previous by thread: Re: reading a file in an applescript.
  • Next by thread: Re: reading a file in an applescript.
  • Index(es):
    • Date
    • Thread