Friday, December 6, 2019

#1 2019-01-29 08:44:16 am

davec0864
Member
Registered: 2018-11-06
Posts: 18

Save As multiple open printed PDF files in Preview

Have a 3rd party SQL application (non-scriptable) that creates 10 reports that are automatically opened in Preview.  Each file has a unique filename, but because they were created by an application, they have no "path" to Save As.  Need help with an Applescript that will ask for a destination path to Save all of the open files, and automatically add a fixed text label to the beginning, and a different fixed text label at the end of each filename when saving.  Example "xxxxx_filename_yyyyyy".  The added text labels will never change.

Model: MacBook Pro
AppleScript: 2.7
Browser: Firefox 64.02
Operating System: macOS 10.13

Offline

 

#2 2019-01-29 09:46:50 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3663

Re: Save As multiple open printed PDF files in Preview

You may try :

Applescript:

set theBeg to "xxxx_" # edit to fit your needs
set theEnd to "_yyyy" # edit to fit your needs

set path2dest to (choose folder) as text

tell application "Preview"
   set theDocs to documents
   
   repeat with aDoc in theDocs
       set docName to name of aDoc
       if docName ends with ".pdf" then
           set doc to text 1 thru -5 of docName
       else
           set doc to docName
       end if
       set trueName to theBeg & doc & theEnd & ".pdf"
       
       save aDoc as "com.adobe.pdf" in file (path2dest & trueName)
   end repeat
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 29 janvier 2019 16:46:34

Last edited by Yvan Koenig (2019-01-29 09:50:21 am)

Offline

 

#3 2019-02-03 07:02:12 am

davec0864
Member
Registered: 2018-11-06
Posts: 18

Re: Save As multiple open printed PDF files in Preview

Thanks!.  Sorry one more quick question.  What would be the script to tell Preview to close all of the open files?

Offline

 

#4 2019-02-03 07:15:42 am

davec0864
Member
Registered: 2018-11-06
Posts: 18

Re: Save As multiple open printed PDF files in Preview

Sorry I'm a moron!  I figured it out!  Thanks!

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)