HT2488: Mac Basics: Automator
Learn about Mac Basics: Automator
-
All replies
-
Helpful answers
-
May 25, 2012 5:23 PM in response to David52by twtwtw,what kind of documents are ou starting with? are they text files, rich text, or Pages documents with complex formatting? it makes a difference in how to approach the task.
-
May 25, 2012 5:28 PM in response to twtwtwby David52,Rich text, with a very few photos (so few, in fact, that I could afford to lose them)---they are recipe
collections taken from different sources (in AppleWorks, no less, then converted to Pages)
I don't know how they were made, it is a collection I have been given to "curate" and make accesible
to different people with different systems.
-
May 25, 2012 6:12 PM in response to David52by twtwtw,well, a quick google turned up this thread. I've tweaked the applescript I found there a bit. Open the applescript editor, paste in the following code, and save it as an application. It will create a new droplet app; drag and drop your files onto it and they'll be converted. You're going to have to let it work. Pages needs to be frontmost while the script runs, which means you won't be able to do anything else until it's done.
I suggest you convert them to pdf files rather than word files (I've set it up to do pdf by default). Everyone can open pdfs (not everyone has Office installed on their machine), pdfs will deal with the pictures and formatting properly, and (unlike Word) pdfs can't be edited easily.
on open fileList
-- change this line to the extension of whatever output file you want.
set newFileExt to "pdf"
-- change this line to point to the folder you want output files to go to. preset to desktop folder.
set savePath to path to desktop folder as text
repeat with thisFile in fileList
set thisFile to thisFile as text
tell application "System Events" to tell disk item thisFile
set {fileName, fileExt} to {get name, get name extension}
end tell
set newName to text 1 thru -(1 + (count of fileExt)) of fileName
tell application "Pages"
activate
-- tricky: apparently Pages is smart enough to create the correct file type based on the extension
set newFileName to savePath & newName & newFileExt
set x to make new document with properties {path:newFileName}
open thisFile
save document 1 in file newFileName
close every window saving no
end tell
end repeat
end open
-
May 26, 2012 7:30 AM in response to David52by Jacques Rioux,Hi,
You can save as (PDF or Word) without (make new document) , Pages can remain in the background
--------------------------------------------------------
on open fileList
-- change this line to point to the folder you want output files to go to. preset to desktop folder.
set savePath to path to desktop folder as text
tell application "Pages" -- iWork 09
repeat with thisFile in fileList
try
tell (open thisFile)
set newName to my getDocName(get name)
save as "SLDocumentTypePDF" in file (savePath & newName) -- Pages automatically adds the extension
close saving no
end tell
end try
end repeat
end tell
end open
on getDocName(t)
if t ends with ".pages" then return text 1 thru -7 of t
return t
end getDocName
--------------------------------------------------------
If you want to save as Word document, replace in the script "SLDocumentTypePDF" by "Microsoft Word 97 - 2004 document"
-
May 26, 2012 7:49 AM in response to Jacques Riouxby twtwtw,Jacques - nice. Just out of curiosity, where is the SLDocumentTypePDF keyword documented? I found another help page that lists out the keywords for pdf, doc, plain text, rich text, and a rich text bundle (SLDocumentTypePDF, SLDocumentTypeMSWord, SLDocumentTypePlainText, SLDocumentTypeRichText, and SLDocumentTypeRichTextBundle), but I don't know if that's the complete list.
-
May 26, 2012 9:31 AM in response to twtwtwby Jacques Rioux,You can get this information in the file "Info.plist" of the application.
In property "Document types" --> Item x --> Document Type Name.
This varies depending on the version of "iWork"
-
May 26, 2012 9:49 AM in response to Jacques Riouxby Jacques Rioux,edit :
but only the types that can export, not the types that can open
example (iWork 09) :"Microsoft Word document" and "SLDocumentTypeAppleWorks" doesn't works, "Microsoft Word 97 - 2004 document" work
-
Jul 10, 2012 9:12 AM in response to Jacques Riouxby RJV Bertin,For some reason, this approach doesn't (always?) work for me, so I combined both approaches above, and added in a bit of logic to make both files share the same modification date. Oh, and each file will be exported to the folder it is in.
on open fileList -- change this line to point to the folder you want output files to go to. preset to desktop folder. -- set savePath to path to desktop folder as text tell application "Pages" -- iWork 09 repeat with thisFile in fileList set curName to name of (info for thisFile) as text set savePath to my dirName(thisFile, true) as text set newName to my getDocName(savePath & curName) set curName to (savePath & curName) set exportFile to newName set openDocument to open thisFile try tell openDocument save as "SLDocumentTypeMSWord" in file exportFile -- Pages automatically adds the extension close saving no end tell on error error_message number error_number --display dialog "Error saving " & exportFile & return & return & error_message buttons {"ok"} default button 1 -- tricky: apparently Pages is smart enough to create the correct file type based on the extension set exportFile to exportFile & ".doc" set x to make new document with properties {path:exportFile} try save openDocument in file exportFile on error error_message number error_number display dialog "Error saving " & exportFile & return & return & error_message buttons {"Cancel"} default button 1 end try close x saving no close openDocument saving no -- get the POSIX paths for the 2 files: set exportFile to POSIX path of exportFile set curName to POSIX path of curName -- construct and execute a command to make the 2 files share the same modification date. do shell script ("sh -c 'touch -r " & curName & " " & exportFile & "'") end try end repeat end tell end open on getDocName(t) if t ends with ".pages:" then return text 1 thru -8 of t if t ends with ".pages" then return text 1 thru -7 of t return "bla" end getDocName on dirName(thePath, wantPath) set thePath to (thePath as text) if thePath contains ":" then set pathDelim to ":" else set pathDelim to "/" end if set saveDelim to AppleScript's text item delimiters set AppleScript's text item delimiters to {pathDelim} set pathAsList to text items of thePath if the last character of thePath is pathDelim then set idx to (the number of text items in thePath) - 2 else set idx to -2 end if if wantPath then set folderName to ((text items 1 through idx of pathAsList) as text) & pathDelim else set folderName to item idx of pathAsList end if set AppleScript's text item delimiters to saveDelim return folderName end dirName -
Jul 15, 2012 4:01 PM in response to RJV Bertinby Jacques Rioux,Hi,
RJV Bertin wrote:
For some reason, this approach doesn't (always?) work for me
try tell openDocument save as "SLDocumentTypeMSWord" in file exportFile -- Pages automatically adds the extension close saving noFor sure it never works. I had already said in my previous message..
You must use --> save as "Word 97-2004 document"