Reading a Text File Into an AppleScript Variable

This is one of those things that you’ll probably do a lot. It’s not too hard in AppleScript but there are a few tricks. Note that there are a wide variety of ways to read from a file, such as reading in a certain number of characters, or until a certain character is encountered.

Reading a Text File Script Screenshot :

Reading a Text file Into an AppleScript Variable

Reading a Text file Into an AppleScript Variable

I generally prefer to read the entire file into a variable and work from there for speed and simplicity.

Apple Script Source Code :

set theFile to (choose file with prompt “Select a file to read:” of type {“TEXT”})

open for access theFile

set fileContents to (read theFile)

close access theFile


5 thoughts on “Reading a Text File Into an AppleScript Variable

  1. Struggling to get your car paid off? Are you mad about the last deal you got?
    Perhaps you’re looking for an automobile now, and you’re
    not sure what to do differently. You’re in the same boat with many other people. Keep reading to find out information regarding what to do next time you enter a dealership.

  2. I love your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone
    to do it for you? Plz reply as I’m looking to design my own blog and would like to find out where u got this from. cheers

Leave a comment