Opening Documents

Opening Pages and Pages-compatible documents is accomplished with the open command from the Standard Suite.

open  : Open a document.

open file reference or a list of file references : The file(s) to be opened.

⇒ document or a list of documents : The opened document(s).

Simply add a file reference, in HFS alias or UNIX POSIX path format, as the direct parameter for the command:

open alias "Macintosh HD:Users:Johnny:Desktop:Q1-Report.pages"

open "/Users/Johnny/Desktop/Q1-Report.pages"

In the script example below, the file reference used as the direct parameter of the open command, is generated by the choose file dialog, which returns a file reference in HFS alias format.

NOTE: the character ¬ (placed at the ends of lines 4-10) is used to indicate that lines 4-11 are part of a single script statement, which has been segmented and placed on separate lines, for the purpose of fitting within the width constrictions of this column.

Open Document
  
01tell application "Pages"
02 activate
03 try
04 set the chosenDocumentFile to ¬
05 (choose file of type ¬
06 {"com.apple.iwork.pages.pages", ¬
07 "com.microsoft.word.doc", ¬
08 "org.openxmlformats.wordprocessingml.document"} ¬
09 default location (path to documents folder) ¬
10 with prompt "Choose the Pages or Microsoft Word document to open:")
11 open the chosenDocumentFile
12 on error errorMessage number errorNumber
13 if errorNumber is not -128 then
14 display alert errorNumber message errorMessage
15 end if
16 end try
17end tell

TIP: The script above uses the path to command to generate a disk reference to a standard user folder. Enumerations for other standard path to command locations include: documents folder/‌downloads folder/home folder/movies folder/music folder/‌pictures folder/public folder/temporary items/shared documents. For more information, view the path to command in the Standard Additions scripting dictionary.

IMPORTANT TIP: Learn how to save and run your favorite scripts using the system-wide Script Menu.

TOP | CONTINUE