O'Reilly logo

AppleScript® Programming for the Absolute Beginner by Jerry Lee Ford

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing AppleScripts That Interact with Text Files

At this point you have learned how to work with traditional MAC and POSIX paths and are now familiar with how to use the file class to establish references to files and folders. With this information now in hand, you are ready to learn how to read from and write to text files. In the sections that follow, you will learn how to open and close files and to extract and modify their contents while you have them open.

Programmatically Opening a Text File

Once you have established a reference to a particular text file, you can open it and begin reading from it or writing text to it. This is accomplished using the open for access command, using the following syntax.

set TargetFile to open for access ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required