Hi.
I work with different products, so depending on the code of the file, I need it to be exported in a different way and in a different folder. And I also have the same files in 32 languages.
I created a script to do that, and it’s working, but it’s not very elegant. I just want to know if someone have better ideas to make it work. As I said, it’s working, but my lack of knowledge made me create very dumb lines I think.
Any help or tip will be good, so I can learn more.
Thank you,
Luiz
tell application "Adobe InDesign 2020"
-- activate
repeat with mgDoc in every document
-- get the file name
set theFilepath to file path of active document as string
set text item delimiters of AppleScript to ":"
set mgFolder to (text items 1 thru -3 of theFilepath as string) & ":"
set text item delimiters of AppleScript to ""
set usePassword to 1 -- depending on the file, I may need to password protect the PDF
-- Get the language code from the file name
set officalName to name of active document
set langName to (text items 9 thru 11 of officalName as string)
-- Check the product names and types
set prodName to (text items 1 thru 3 of officalName as string) -- this is the name of the product
set matType to (text items 6 thru 8 of officalName as string) -- this is the type of product
set prodPath to "" -- where to save
set prodSubPath to "" -- maybe will be saved in a subfolder
-- will a password be needed?
set theListmat to {"COR", "CER"}
set theListProd to {"EAU", "WTT", "RYS", "STL", "STK", "LGW", "COR"}
if matType is in theListmat then -- if the product is in the list, it will require a password
set usePassword to 1
else
set usePassword to 2
end if
if prodName is in theListProd then -- if the product is in the list, it will require a password
set usePassword to 1
else
set usePassword to 2
end if
-- now, define the destination folders
if prodName = "COR" then
set prodPath to "CORE"
set prodSubPath to "Books"
end if
if matType = "CER" then set prodPath to "CERT"
if prodName = "EAU" then set prodPath to "EAU"
if prodName = "WTT" then set prodPath to "WTTS"
if prodName = "RYS" then set prodPath to "RYSB"
if prodName = "STL" then set prodPath to "SFT1"
if prodName = "STK" then set prodPath to "SFT2"
if prodName = "LGW" then set prodPath to "CORE"
-- these are the "non-password" ones
if prodName = "LEA" then set prodPath to "WTTS"
if prodName = "STE" then set prodPath to "STECOM"
if prodName is in {"CER", "FGD", "INS", "MUL", "TCS", "TES", "TPF", "TRO", "TSH"} and matType = "OTH" then
set prodPath to "CORE"
set prodSubPath to "Additional materials"
end if
if prodName = "PRO" and matType = "SHE" then
set prodPath to "CORE"
set prodSubPath to "Additional materials"
end if
if prodName = "CON" then
set prodPath to "CORE"
set prodSubPath to "CONOVE"
end if
--- Export sequence
set mgExport to "Para revisar"
set mgSubFolder to langName
set mgNameExtra to "_Consultant"
set properties of PDF export preferences to properties of PDF export preset mgExport
set page range of PDF export preferences to all pages
if usePassword = 1 then -- if a password is requested for the file, here it is
tell PDF export preferences
set use security to true
set change security password to "XXXXX"
set disallow changing to true
set disallow copying to true
set disallow document assembly to true
set disallow extraction for accessibility to true
set disallow form fill in to true
set disallow hi res printing to true
set disallow plaintext metadata to true
set disallow printing to true
end tell
end if
set mgDocName to name of active document
set text item delimiters of AppleScript to "."
set mgShortName to text item 1 of mgDocName
set text item delimiters of AppleScript to ""
set mgFilePath to mgFolder & mgSubFolder & ":" & prodPath & ":" & mgShortName & mgNameExtra & ".pdf" as string
-- setup the path to export
if prodSubPath is not "" then -- if the product is inside a subfolder it includes the "prodSubPath"
set mgFilePath to "Macintosh HD:Users:XXXXXX:Desktop:Consultant Files:Source PDFs:" & mgSubFolder & ":" & prodPath & ":" & prodSubPath & ":" & mgShortName & mgNameExtra & ".pdf" as string
else
set mgFilePath to "Macintosh HD:Users:XXXXXX:Desktop:Consultant Files:Source PDFs:" & mgSubFolder & ":" & prodPath & ":" & mgShortName & mgNameExtra & ".pdf" as string
end if
-- create folders if they do not exist
tell application "Finder"
if (exists folder mgSubFolder of folder "Macintosh HD:Users:XXXXXX:Desktop:Consultant Files:Source PDFs:") is false then -- first, create a folder for the language
make new folder at "Macintosh HD:Users:XXXXXX:Desktop:Consultant Files:Source PDFs:" with properties {name:mgSubFolder}
end if
set newPath1 to "Macintosh HD:Users:XXXXXX:Desktop:Consultant Files:Source PDFs:" & mgSubFolder & ":"
if (exists folder prodPath of folder newPath1) is false then -- then create a folder for the product
make new folder at newPath1 with properties {name:prodPath}
end if
if prodSubPath is not "" then -- and if needed, a subfolder
set newPath1 to newPath1 & prodPath & ":"
if (exists folder prodSubPath of folder newPath1) is false then
make new folder at newPath1 with properties {name:prodSubPath}
end if
end if
end tell
tell active document
export format PDF type to mgFilePath without showing options
end tell
close active document saving no
end repeat
end tell