-- word2pages.applescript -- Batch open Word .doc/.docx and save as .pages -- Tested: macOS High Sierra 10.13.6, macOS High Sierra 10.14.2, Pages v7.3 -- Usage: Interactive, double-click application. -- Version: 1.2 -- Author: vikingOSX, 2019-01-19, Apple Support Communities, No Warranties. use scripting additions property valid_kind : {"Microsoft Word Document"} property app_icon : "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/MultipleItemsIcon.icns" property fileCnt : (0 as integer) property workflow : "~/Library/Workflows/word_files_folders.workflow" -- double-click application to run it on run set {fileList, retObjs} to {{}, {}} try set retObjs to paragraphs of (do shell script "/usr/bin/Automator " & workflow & " | awk '!/\\(|\\)/ {gsub(/\\x5c|,|\"/, \"\", $1);print $1;next}'") on error errmsg number errnbr my error_handler(errnbr, errmsg) quit end try if (count of retObjs) is 0 then display alert "User cancelled." quit end if -- must transform UNIX file paths to aliased POSIX file paths for main processing repeat with anItem in retObjs copy (anItem as POSIX file as alias) to the end of fileList end repeat -- the opened file list will simply fall into the following open handler open fileList end run on open fileList tell application "Pages" to set pvers to version of it if pvers < "5.5" then display alert "You need a newer version of Pages" giving up after 10 quit end if repeat with anItem in fileList try tell application "Finder" set akind to kind of anItem if akind is equal to "Folder" then set docList to (every item in entire contents of folder anItem whose kind is in valid_kind) as alias list repeat with afile in docList my save_as_Pages(afile) end repeat else if akind is in valid_kind then my save_as_Pages(anItem) end if end tell on error errmsg number errnbr my error_handler(errnbr, errmsg) quit end try end repeat tell application "System Events" display dialog "Processing Complete" & return & tab & " Word documents converted to Pages: " & (fileCnt as text) buttons {"Done"} default button "Done" with title "Pages Conversion Results" with icon POSIX file app_icon as alias end tell quit end open on save_as_Pages(theFile) -- handle .doc and .docx files replace extension with .pages set DELIM to {".doc", ".docx"} set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, DELIM} set pages_out to item 1 of text items of (theFile as text) & ".pages" set AppleScript's text item delimiters to TID -- close access (open for access pages_out with write permission) tell application "Pages" try open theFile as alias delay 1 with timeout of 600 seconds close front document saving yes saving in file pages_out end timeout set fileCnt to (fileCnt + 1) as integer on error errmsg number errnbr my error_handler(errnbr, errmsg) quit end try end tell try tell application "Finder" if exists (item pages_out as alias) then set extension hidden of (item pages_out as alias) to false end if end tell on error errmsg number errnbr my error_handler(errnbr, errmsg) quit end try return end save_as_Pages on error_handler(nbr, msg) return display alert "[ " & nbr & " ] " & msg as critical giving up after 10 end error_handler on quit {} -- perform these cleanup items, and then really quit tell application "Pages" to if it is running then quit set fileCnt to (0 as integer) set pages_out to "" continue quit end quit