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
You may try :
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
Thanks!. Sorry one more quick question. What would be the script to tell Preview to close all of the open files?
Sorry I’m a moron! I figured it out! Thanks!