View Full Version : Help tweaking applescript in service workflow

May 19, 2011, 10:12 AM
Would love any help with this to improve my workflow:

I found an applescript online that I have used to build a service within automator. It allows me to right click on a .pages document and convert it to pdf. Currently though, the naming of the file isn't working quite as I expected:

[right click, run pages2pdf service]
(output-->) Example.pagesExample.pdf

Here is the applescript:

on run {input, parameters}

-- based on code from http://pagesfaq.blogspot.com/2006/11/i-have-one-thousand-pages-documents-to.html

--on open theFiles
set outputFiles to {}
set theFiles to input

tell application "Pages"
repeat with aFile in theFiles
open aFile
set docName to name of front document
set docPath to path of front document
-- Remove .pages extension.
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to ".pages"
-- Add .doc extension.
set docName to first text item of docName
set AppleScript's text item delimiters to prevTIDs
-- Save file in same folder
set docPathAndName to docPath & docName
save front document as "SLDocumentTypePDF" in docPathAndName
close front document
set end of outputFiles to docPathAndName & ".pdf"
end repeat
end tell
--end open

return outputFiles
end run

Any tips, suggestions, answers?

(running OS X 10.6.7)