• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

(AppleScript) The variable scriptResources_PrintStudio is not defined.

New Here ,
Oct 18, 2019 Oct 18, 2019

Copy link to clipboard

Copied

Hi, Can anyone resolve the error:

Thanks in Advance

Simon

 

on run {input, parameters}

--The script should have two options

--Option 1: Channel

--Option 2: Retail

set questionFunctionality to display dialog "Please select the functionality:" buttons {"Export", "Slug Updater", "Cancel"}

set answerFunctionality to button returned of questionFunctionality

 

set questionStudio to display dialog "Please select your artwork type:" buttons {"Channel", "Retail", "Cancel"}

set answerStudio to button returned of questionStudio

set theDocPath to path to documents folder as Unicode text

 

--set theFilesScript to theDocPath & "Adobe Scripts:scriptResources_PrintStudio:main_library.jsx"

set theMainScript to theDocPath & "Adobe Scripts:scriptResources_PrintStudio:export.jsx"

set pdfSetting to theDocPath & "Adobe Scripts:scriptResources_PrintStudio:export:Studio-PDF.joboptions"

 

(*The folderstructures to be created/checked are different

based on Channel or Retai*)

 

--set scriptResources_PrintStudio to {"_jpg", "_pdf", "_old"}

--set ir_subFolderNames to {"_DSS", "_old"}

--set ic_mainFolderNames to {"1_jpg", "2_pdf", "3_old"}

--set ic_subFolderNames to {"1_old"}

 

if answerStudio is equal to "Channel" then

set scriptResources_PrintStudio to ic_mainFolderNames

set i_subFolderNames to ic_subFolderNames

else if answerStudio is equal to "Retail" then

set scriptResources_PrintStudio to scriptResources_PrintStudio

set i_subFolderNames to ir_subFolderNames

end if

 

--The be run by either having docs opened or by selecting these files

tell application "Adobe InDesign CC 2019"

with timeout of 3600 seconds

launch

activate

set countDocs to (count of documents) as number

set masterFilesSelected to null

 

(*if input is not {} then

set thePathFilename to {}

repeat with i from 1 to (input count)

copy (POSIX path of (item i of input as string)) to end of thePathFilename

end repeat

set masterFilesSelected to thePathFilename

else*)

 

if countDocs is equal to 0 then

 

set mainINDDFiles to choose file with prompt "Please choose one or more INDD files:" with multiple selections allowed

 

if mainINDDFiles is {} then

display dialog "No files were selected" buttons {"OK"}

tell me to quit

 

else if (mainINDDFiles count) is equal to 1 then

set thePathFilename to {}

copy (POSIX path of (mainINDDFiles as string)) to end of thePathFilename

set masterFilesSelected to thePathFilename

 

else

set thePathFilename to {}

repeat with i from 1 to (mainINDDFiles count)

copy (POSIX path of (item i of mainINDDFiles as string)) to end of thePathFilename

end repeat

set thePathFilename to thePathFilename

set masterFilesSelected to thePathFilename

end if

 

else

(* Not needed, user only to work with active document

set argumentCondition1 to "OpenedFiles"

set mainINDDFiles to do script theFilesScript language javascript with arguments {argumentCondition1}

repeat with i from 1 to (count of mainINDDFiles)

--set tempPath to (file path of document i) as string

copy item i of mainINDDFiles to end of thePathFilename

end repeat

set thePathFilename to thePathFilename

set masterFilesSelected to thePathFilename *)

 

set thePathFilename to {}

set mainINDDFiles to ((file path of active document) as string) & (name of active document) as string

set end of thePathFilename to POSIX path of mainINDDFiles as string

set masterFilesSelected to thePathFilename

end if

 

--end if

 

repeat with i from 1 to count of masterFilesSelected

set theDoc to item i of masterFilesSelected

--display dialog theDoc

set argumentCondition2 to "CollectPaths"

set thePath to do script theFilesScript language javascript with arguments {argumentCondition2, theDoc}

set theFilePath to POSIX path of thePath as string

 

tell application "System Events"

set theFolders to every folder of folder theFilePath

--Reading the main folder to identify whether it is empty

--If it is empty, create the folder structure

if (count of theFolders) is equal to 0 then

set movePdf to false

repeat with f from 1 to (count of scriptResources_PrintStudio)

set mainFolderPath to make new folder at folder theFilePath with properties {name:item f of scriptResources_PrintStudio}

set posixMainFolderPath to POSIX path of mainFolderPath as string

 

if answerStudio is equal to "Retail" then

if item f of scriptResources_PrintStudio is equal to item 1 of scriptResources_PrintStudio then

make new folder at folder posixMainFolderPath with properties {name:item 1 of i_subFolderNames}

else if item f of scriptResources_PrintStudio is equal to item 2 of scriptResources_PrintStudio then

make new folder at folder posixMainFolderPath with properties {name:item 2 of i_subFolderNames}

end if

else

if item f of scriptResources_PrintStudio is equal to item 2 of scriptResources_PrintStudio then

make new folder at folder posixMainFolderPath with properties {name:item 1 of i_subFolderNames}

--make new folder at folder posixMainFolderPath with properties {name:item 2 of i_subFolderNames}

end if

end if

end repeat

 

--If it is not empty, then start identifying the type of folders in there

--We are searching for an exact match of the strings

 

 

else

repeat with f from 1 to (count of theFolders)

set folderToClassify to item f of theFolders

set posixFolderToClassify to POSIX path of folderToClassify as string

 

--Old folder

if name of folder posixFolderToClassify is equal to item 3 of scriptResources_PrintStudio then

--set oldFolderExist to true

set theOldFolder to posixFolderToClassify

--else

--set oldFolderExist to false

end if

 

--Jpg folder

if name of folder posixFolderToClassify is equal to item 1 of scriptResources_PrintStudio then

--set jpgFolderExist to true

set theJpgFolder to posixFolderToClassify

 

(*--DSS jpg subfolder

set theJpgSubFolders to every folder of folder theJpgFolder

repeat with s from 1 to count of theJpgSubFolders

set potentialSubFolder to item s of theJpgSubFolders

if name of potentialSubFolder is equal to item 1 of i_subFolderNames then

--set dssFolderExist to true

set dssJpegSubFolder to item s of theJpgSubFolders

set posixdssJpegSubFolder to POSIX path of dssJpegSubFolder as string

--else

--set dssFolderExist to false

end if

end repeat*)

--else

--set jpgFolderExist to false

--set dssFolderExist to false

end if

 

--pdf folder

if name of folder posixFolderToClassify is equal to item 2 of scriptResources_PrintStudio then

--set pdfFolderExist to true

set thePdfFolder to posixFolderToClassify

 

--Old pdf folder

set thePdfSubFolders to every folder of folder thePdfFolder

repeat with p from 1 to count of thePdfSubFolders

set potentialPdfSubFolder to item p of thePdfSubFolders

if answerStudio is equal to "Retail" then

if name of potentialPdfSubFolder is equal to item 2 of i_subFolderNames then

--set oldPdfFolderExist to true

set oldPdfSubFolder to item p of thePdfSubFolders

set posixoldPdfSubFolder to POSIX path of oldPdfSubFolder as string

--else

--set oldPdfFolderExist to false

end if

else

if name of potentialPdfSubFolder is equal to item 1 of i_subFolderNames then

set oldPdfSubFolder to item p of thePdfSubFolders

set posixoldPdfSubFolder to POSIX path of oldPdfSubFolder as string

else if name of potentialPdfSubFolder is equal to item 2 of i_subFolderNames then

set killedPdfSubFolder to item p of thePdfSubFolders

set posixKilledPdfSubFolder to POSIX path of killedPdfSubFolder as string

end if

end if

end repeat

 

--else

--set pdfFolderExist to false

--set oldPdfFolderExist to false

 

end if

end repeat

 

--------------------------------------

--Understand how many of those folders actually exist

--This functionality was not required but it should reduce any user error and improve robutness

--This needs to be improved/finished think about the logic

(*set checkingList to {oldFolderExist, jpgFolderExist, dssFolderExist, pdfFolderExist, oldPdfFolderExist}

set missingFolders to {}

repeat with c from 1 to count of checkingList

if item c of checkingList is equal to false then

set end of missingFolders to item c of checkingList

end if

end repeat*)

-----------------------------------------

 

--After everything is identified, we start moving old files if needed

-------------------------------------- see if it is possible to create a function as it is the same functionality

 

(*--Moving JPEGs

set jpgFiles to (every file of folder theJpgFolder whose name extension is "jpeg")

set dssJpgFiles to (every file of folder posixdssJpegSubFolder whose name extension is "jpeg")

if (count of dssJpgFiles) is greater than 0 then

repeat with d from 1 to count of dssJpgFiles

set oldDssJpg to item d of dssJpgFiles

set posixOldDssJpg to POSIX path of oldDssJpg as string

try

delete file posixOldDssJpg

end try

end repeat

end if

if (count of jpgFiles) is greater than 0 then

repeat with j from 1 to count of jpgFiles

set oldJpg to item j of jpgFiles

set posixOldJpg to POSIX path of oldJpg as string

try

move posixOldJpg to folder theOldFolder with replacing

end try

end repeat

end if*)

 

--Moving PDFs

set pdfFiles to (every file of folder thePdfFolder whose name extension is "pdf")

if (count of pdfFiles) is greater than 0 then

repeat with p from 1 to count of pdfFiles

set oldPdf to item p of pdfFiles

set posixOldPdf to POSIX path of oldPdf as string

try

move posixOldPdf to folder posixoldPdfSubFolder

on error

display dialog "We could not move the \"old\" InDesign File into the \"old\" folder. This might be because this file already exists in this folder."

end try

end repeat

end if

 

--Moving INDDs

set inddFiles to (every file of folder theFilePath whose name extension is "indd")

if (count of inddFiles) is greater than 0 then

repeat with i from 1 to count of inddFiles

set oldIndd to item i of inddFiles

set posixOldIndd to POSIX path of oldIndd as string

set thePathSplit to my theSplit(posixOldIndd, "/")

set theDocSplit to my theSplit(theDoc, "/")

set x to count of thePathSplit

set y to count of theDocSplit

set theNamePath to item x of thePathSplit

set theNameDoc to item y of theDocSplit

if theNamePath is not equal to theNameDoc then

try

move posixOldIndd to folder theOldFolder

on error

display dialog "We could not move the \"old\" InDesign File into the \"old\" folder. This might be because this file already exists in this folder."

end try

end if

end repeat

end if

 

 

end if

end tell

if answerStudio is equal to "Retail" then

set txtInfo to my readVarsRetail(theFilePath)

 

set languageString to item 1 of txtInfo

set languageCodesFull to my theSplit(languageString, "/")

 

set lnOnetxt to my RemoveDuplicates(languageCodesFull)

set lnTwotxt to item 2 of txtInfo

set lnThreetxt to item 3 of txtInfo

 

set vendorsString to item 4 of txtInfo

set retailVendors to my theSplit(vendorsString, ",")

set lnFourtxt to my theCleanUp(retailVendors)

set retailVendorsClean to my RemoveDuplicates(retailVendors)

 

set substrateString to item 5 of txtInfo

set lnFivetxt to my theSplit(substrateString, ",")

--set retailSubstrate to mxy RemoveDuplicates(retailSubstrateFull)

 

set lnSixtxt to item 6 of txtInfo

set barcode to item 7 of txtInfo

set jobNum to item 8 of txtInfo

else

set txtInfo to my readVarsChannel(theFilePath)

set lnOnetxt to ""

set lnTwotxt to item 2 of txtInfo

set lnThreetxt to item 3 of txtInfo

set lnFourtxt to item 4 of txtInfo

set lnFivetxt to ""

set lnSixtxt to ""

set retailVendorsClean to ""

set barcode to item 1 of txtInfo

set jobNum to ""

end if

 

if answerFunctionality is equal to "Slug Updater" then

set argumentCondition3 to "VersionUp"

set theFileName to do script theFilesScript language javascript with arguments {argumentCondition3, theDoc}

set theActualName to name of active document as string

set theVersionName to item 1 of theFileName as string

set theCurrentVersion to item 2 of theFileName as string

set versionList to {theActualName, theVersionName}

set versionUp to choose from list versionList with title "Version" with prompt "Do you want to update existing version number?" default items theActualName

set theVersionAnswer to versionUp as string

 

if theVersionAnswer is equal to "false" then

tell me to quit

set endScript to true

else

set endScript to false

end if

 

tell application "System Events"

set theProducerName to long user name of (system info)

end tell

else

set theVersionAnswer to ""

set theProducerName to ""

set endScript to false

set theCurrentVersion to ""

set theVersionAnswerNoExt to ""

end if

 

do script theMainScript language javascript with arguments {theDoc, answerStudio, lnOnetxt, lnTwotxt, lnThreetxt, lnFourtxt, lnFivetxt, lnSixtxt, retailVendorsClean, barcode, answerFunctionality, theVersionAnswer, theProducerName, jobNum, endScript, theCurrentVersion}

 

if answerFunctionality is equal to "Slug Updater" and answerStudio is equal to "Retail" then

 

do script theFilesScript language javascript with arguments {barcode, theDoc}

 

end if

 

if answerFunctionality is equal to "Slug Updater" then

tell application "System Events"

set theFolders to every folder of folder theFilePath

repeat with f from 1 to (count of theFolders)

set folderToClassify to item f of theFolders

set posixFolderToClassify to POSIX path of folderToClassify as string

 

--Old folder

if name of folder posixFolderToClassify is equal to item 3 of scriptResources_PrintStudio then

--set oldFolderExist to true

set theOldFolder to posixFolderToClassify

--else

--set oldFolderExist to false

end if

end repeat

set inddFiles to (every file of folder theFilePath whose name extension is "indd")

if (count of inddFiles) is greater than 0 then

repeat with i from 1 to count of inddFiles

set oldIndd to item i of inddFiles

set posixOldIndd to POSIX path of oldIndd as string

set thePathSplit to my theSplit(posixOldIndd, "/")

--set theDocSplit to my theSplit(theDoc, "/")

set x to count of thePathSplit

--set y to count of theDocSplit

set theNamePath to item x of thePathSplit as string

--set theNameDoc to item y of theDocSplit

if theNamePath is not equal to theVersionAnswer then

try

move posixOldIndd to folder theOldFolder

on error

display dialog "We could not move the \"old\" InDesign File into the \"old\" folder. This might be because this file already exists in this folder."

end try

end if

end repeat

end if

(*if movePdf is equal to true then

set pdfFiles to (every file of folder thePdfFolder whose name extension is "pdf")

if (count of pdfFiles) is greater than 0 then

repeat with p from 1 to count of pdfFiles

set oldPdf to item p of pdfFiles

set posixOldPdf to POSIX path of oldPdf as string

set thePathSplitPdf to my theSplit(posixOldPdf, "/")

set z to count of thePathSplitPdf

set theNamePathPdf to item z of thePathSplitPdf as string

set theVersionAnswerNoFormat to item 1 of my theSplit(theVersionAnswer, ".")

set theVersionAnswerPdf to theVersionAnswerNoFormat & ".pdf" as string

if theNamePathPdf is not equal to theVersionAnswerPdf then

try

move posixOldPdf to folder posixoldPdfSubFolder

on error

display dialog "We could not move the \"old\" InDesign File into the \"old\" folder. This might be because this file already exists in this folder."

end try

end if

end repeat

end if

end if*)

end tell

end if

end repeat

 

display dialog "Finished" as string

 

--masterFileSelected and masterOption are used in the mainScripts in order to collect all the INDD files and start working with them

--set theScript to do script theMainScript language javascript with arguments {masterFilesSelected, masterOption}

 

end timeout

end tell

end run

 

on theCleanUp(theList)

 

set outputList to {}

 

repeat with i from 1 to count of theList

 

set cleanthisItem to item i of theList

 

if cleanthisItem ends with space then

set thisItem to text 1 thru -2 of cleanthisItem

else if cleanthisItem starts with space then

set thisItem to cleanthisItem as string

else

set thisItem to cleanthisItem as string

end if

 

set end of outputList to thisItem

 

end repeat

 

return outputList

 

end theCleanUp

 

on readVarsRetail(pth)

 

set txtFile to POSIX file (pth & "VariableData.txt")

 

set txtLines to paragraphs of (read file txtFile as «class utf8»)

 

set barcode to item 1 of txtLines

set projectName to item 2 of txtLines & " "

set jobNum to item 3 of txtLines & " "

set store to item 4 of txtLines & " "

set langCodes to my replaceCommasWithFwardSlash(item 5 of txtLines) & " "

set languageCodes to my replaceCommasWithFwardSlash(item 5 of txtLines)

set vendors to item 6 of txtLines & " "

set substrate to item 7 of txtLines & " "

set yrMonth to item 8 of txtLines & " "

set content to item 9 of txtLines & " "

 

set descriptionString to projectName & "

" & yrMonth & "| " & content & "| " & langCodes & "| " & store

set flagString to yrMonth & "| " & content & "| " & langCodes & "| " & store

 

return {languageCodes, descriptionString, flagString, vendors, substrate, yrMonth, barcode, jobNum}

 

end readVarsRetail

 

on readVarsChannel(pth)

 

set txtFile to POSIX file (pth & "VariableData.txt")

 

set txtLines to paragraphs of (read file txtFile as «class utf8»)

 

set delivName to item 1 of txtLines

set jobNum to item 2 of txtLines

set product to item 3 of txtLines

set variant to item 4 of txtLines

 

return {delivName, jobNum, product, variant}

 

end readVarsChannel

 

on theSplit(theString, theDelimiter)

-- save delimiters to restore old settings

set oldDelimiters to AppleScript's text item delimiters

-- set delimiters to delimiter to be used

set AppleScript's text item delimiters to theDelimiter

-- create the array

set theArray to every text item of theString

-- restore the old setting

set AppleScript's text item delimiters to oldDelimiters

-- return the result

return theArray

end theSplit

 

on replaceCommasWithFwardSlash(theList)

set oldDelimiters to AppleScript's text item delimiters

set AppleScript's text item delimiters to ","

set theArray to every text item of theList

set AppleScript's text item delimiters to "/"

set theResult to theArray as string

return theResult

end replaceCommasWithFwardSlash

 

on RemoveDuplicates(inputList)

 

set outputList to {}

 

repeat with i from 1 to length of inputList

 

--  We make testItem a single-item list to ensure

-- that sublists of the inputList are properly

-- looked for in the outputlist.

 

set cleanthisItem to item i of inputList

if cleanthisItem ends with space then

set thisItem to text 1 thru -2 of cleanthisItem

else

set thisItem to cleanthisItem as string

end if

 

set testItem to {thisItem}

 

if (outputList does not contain testItem) then

 

set end of outputList to thisItem

 

end if

 

end repeat

 

return outputList

 

end RemoveDuplicates

TOPICS
Scripting

Views

253

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Oct 18, 2019 Oct 18, 2019

Copy link to clipboard

Copied

The script references some resources wich should be located in the user's Documents folder:

"Adobe Scripts:scriptResources_PrintStudio:main_library.jsx"

"Adobe Scripts:scriptResources_PrintStudio:export.jsx"

"Adobe Scripts:scriptResources_PrintStudio:export:Studio-PDF.joboptions"

Make sure they are in place.

 

Some lines of the code are commented out, for example:

clipboard_image_0.png

Here the scriptResources_PrintStudio variable is set to ic_mainFolderNames which is undefined because a few lines above it is commented out. That's why you get the error.

I guess it's not the final version, or someone has messed it up.

— Kas

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 18, 2019 Oct 18, 2019

Copy link to clipboard

Copied

LATEST
Super thanks a lot

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines