Why would I get an error when running this script in CC2017, it was originally created for CC2015 and still works fine,
but when I try to run in CC2017 I get an error telling me the folder, which its creates just fine, does not exist.
tell application id "com.adobe.InDesign"
set mgFolder to file path of active document
set mgName to name of active document
set text item delimiters of AppleScript to ""
end tell
tell application "Finder"
if (exists folder "2pp_Page_pdfs" of folder mgFolder) is false then
make folder at mgFolder with properties {name:"2pp_Page_pdfs"}
end if
end tell
tell application id "com.adobe.InDesign"
set mgPageCount to count pages of active document
repeat with mgPages from 1 to mgPageCount by 2
set page range of PDF export preferences to ((mgPages as string) & "-" & (mgPages + 1) as string)
tell active document
set mgFrames to (text frames of page mgPages whose name of item layer is "Code Layer")
set mgFrame to item 1 of mgFrames
set mgText to contents of item 1 of mgFrame
set mgFilePath to mgFolder & "2pp_Page_pdfs:" & mgText & "_L" & mgPages & ".pdf" as string
export format PDF type to mgFilePath using "GENERIC" without showing options
end tell
end repeat
display dialog "2pp PDFs CREATED" buttons {"OK"} default button 1
end tell
Running iMac with Sierra.
Are you sure that there is a colon at the end of mgFolder ?
It’s what is assumed by the instruction:
set mgFilePath to mgFolder & "2pp_Page_pdfs:" & mgText & "_L" & mgPages & ".pdf" as string
Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) mardi 13 juin 2017 17:40:58
Don’t think its the colon, that tells it to go into the folder thats been created.
I have at the moment, for various reasons, 2 profiles on my mac lets call them profile a and b, I have now found that depending which one I log onto first, the script will work on that profile, because I need to toggle between both profiles, to get the script to work I can log out of the other profile and it will work, not ideal, but I will soon dispense with the alternative profile and all should be well.
Thanks for looking.
JP
If mgFolder doesn’t end with a colon, the new folder will be correctly created but the path used to reach it will be wrong.
Run this short script for see.
set mgFolder to (path to desktop folder as text) & "fake folder" # Deliberately omit ending colon
set folderName to "2pp_Page_pdfs"
tell application "Finder"
if (exists folder folderName of folder mgFolder) is false then
make folder at mgFolder with properties {name:folderName}
end if
end tell
tell application "Finder"
# path assuming that mgFolder ends with a colon
set withoutColon to exists folder (mgFolder & folderName) --> false
# path inserting a colon
set withColon to exists folder (mgFolder & ":" & folderName) --> true
# code playing safe:
if mgFolder does not end with ":" then set mgFolder to mgFolder & ":"
set safety to exists folder (mgFolder & folderName) --> true
end tell
{withoutColon, withColon, safety} --> {false, true, true}
Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) mercredi 14 juin 2017 10:42:24