Copy link to clipboard
Copied
Hi All,
I got below error while run the script. It is an photoshop version error? Im using Big Sur OS Photoshop 2021 v22.3.0. Please share your thoughts.
Copy link to clipboard
Copied
Please share the code using the <\> button.
Copy link to clipboard
Copied
Hi Stephen,
I cant able to share the code its contain multiple number of line, and the Applescript is the main script which will integrate with supporting scripts(JavaScript) to execute.
Could you please outlined what the exact issue is?
I will share the main applescript below for your reference:
set theResult to every paragraph of (do shell script "mdfind 'kMDItemContentTypeTree == \"com.apple.application\"c' | sort")
set systemApps to {}
set applicationsApps to {}
set Version2021 to "false" as string
repeat with i from 1 to number of items in theResult
set end of systemApps to item i of theResult
if item i of theResult contains "Adobe Photoshop 2021" then
set end of applicationsApps to item i of theResult
set Version2021 to "true" as string
exit repeat
end if
end repeat
if Version2021 is equal to "false" then
display alert "This system do not have Adobe Photoshop 2021"
tell me to quit
else
--Library of scripts to be called
set theDocPath to path to documents folder as Unicode text
set thePath to theDocPath & "Adobe Scripts:DO_NOT_DELETE_scriptResources:"
set theScriptFiles to thePath & "digital:be_library:DP_JS1.jsx" as string --Collects Files
set theScriptArtboardFiles to thePath & "digital:be_library:DP_JS2.jsx" as string --Runs the Functionality
set theScriptMain to thePath & "digital:be_library:DP_JS3.jsx" as string --Runs the Functionality
tell application "System Events"
if exists file theScriptFiles then
else
display dialog "Supporting file missing
" & theScriptFiles
tell me to quit
end if
if exists file theScriptArtboardFiles then
else
display dialog "Supporting file missing
" & theScriptArtboardFiles
tell me to quit
end if
if exists file theScriptMain then
else
display dialog "Supporting file missing
" & theScriptMain
tell me to quit
end if
end tell
tell application "Adobe Photoshop 2021" --Adobe Photoshop 2021
with timeout of 3600 seconds
if it is not running then
set wasRunning to "False"
set countDocs to 0
launch
else if it is running then
set countDocs to (count of document) as number
set wasRunning to "True"
end if
if it is running then
activate
set countOfOpenDocs to (countDocs + 1)
end if
--UI: Allow the user to either Select Folders containing PSDs Files or allow the user to select PSD/PSB Files directly
--The way the user selects the files affects DP_JS1.jsx
--If the user select the files, then we do not need to "dig" into multiple Folders
--However, if the user select folders, then we need to go through each folder/sub-folder looking for PSD or PSB Files
set selectMainDialog to display dialog "Do you want to package ALAC or CA digital files?" buttons {"ALAC", "CA", "Cancel"}
set answerMainDialog to button returned of selectMainDialog
set optionDialog to display dialog "Do you want to select folders or .psd/.psb files?" buttons {"Select Folders", "Select .psd/.psb Files", "Cancel"}
set optionAnswer to button returned of optionDialog
if optionAnswer is equal to "Select Folders" then
set theSelection to (choose folder with prompt "Please choose one or more folders:" with multiple selections allowed)
if theSelection is {} then
display dialog "No folders were selected" buttons {"OK"}
tell me to quit
else if (theSelection count) is equal to 1 then
set thePathFolder to {}
copy (POSIX path of (theSelection as string)) to end of thePathFolder
set filesOrFoldersSelected to thePathFolder
else
set thePathFolder to {}
repeat with i from 1 to (theSelection count)
copy (POSIX path of (item i of theSelection as string)) to end of thePathFolder
end repeat
set thePathFolder to thePathFolder
set filesOrFoldersSelected to thePathFolder
end if
--return filesOrFoldersSelected
end if
if optionAnswer is equal to "Select .psd/.psb Files" then
set theSelection to (choose file with prompt "Please choose one or more files:" with multiple selections allowed)
if theSelection is {} then
display dialog "No files were selected" buttons {"OK"}
tell me to quit
else if (theSelection count) is equal to 1 then
set thePathFilename to {}
copy (POSIX path of (theSelection as string)) to end of thePathFilename
set filesOrFoldersSelected to thePathFilename
else
set thePathFilename to {}
repeat with i from 1 to (theSelection count)
copy (POSIX path of (item i of theSelection as string)) to end of thePathFilename
end repeat
set thePathFilename to thePathFilename
set filesOrFoldersSelected to thePathFilename
end if
--return thePathFilename
end if
if optionAnswer is equal to "Cancel" then
tell me to quit
end if
--UI: OutputLocation
set outputLocation to choose folder with prompt "Please select output location:" --Returns Path in Applescript
set outputLocationJS to POSIX path of outputLocation as string --Converts Path in Javascript
--UI: Allow the user to edit the output folder
--i.e. Output Folder by default = The Language Code (e.g. FRFR, ESES, etc)
--With this functionality, the output folder could be = FRFR_This_is_bespoke_naming, ESES_This_is_bespoke_name
set renameOutputOptions to display dialog "Do you want to edit the output folder names?" buttons {"Yes", "No", "Cancel"}
set renameOutputAnswer to button returned of renameOutputOptions
if renameOutputAnswer is equal to "Yes" then
set theRenameInput to text returned of (display dialog "Please enter a name for the output folder(s):" default answer "")
end if
if renameOutputAnswer is equal to "No" then
set theRenameInput to "<!NO_INPUT!>"
end if
if renameOutputAnswer is equal to "Cancel" then
tell me to quit
end if
--UI:Colour Labels
--Refer to the User Guide to understand this
set labelOptions to display dialog "Do you want to remove the colour labels?" buttons {"Yes", "No", "Cancel"}
set labelAnswer to button returned of labelOptions
if labelAnswer is equal to "Yes" then
set theLabelAnswer to "Yes Labels"
end if
if labelAnswer is equal to "No" then
set theLabelAnswer to "No Labels"
end if
if labelAnswer is equal to "Cancel" then
tell me to quit
end if
--UI:Rasterise
--Refer to the User Guide to understand this
set rasterizeOptions to display dialog "Do you want to rasterize layers?" buttons {"Yes", "No", "Cancel"}
set rasterizeAnswer to button returned of rasterizeOptions
if rasterizeAnswer is equal to "Yes" then
set theRasterizeAnswer to "Do rasterize"
end if
if rasterizeAnswer is equal to "No" then
set theRasterizeAnswer to "Do not rasterize"
end if
if rasterizeAnswer is equal to "Cancel" then
tell me to quit
end if
set hiddenLayersOptions to display dialog "Do you want to delete all the hidden/unused layers?" buttons {"Yes", "No", "Cancel"}
set hiddenLayersAnswer to button returned of hiddenLayersOptions
if hiddenLayersAnswer is equal to "Yes" then
set thehiddenLayers to "Yes HiddenLayers"
end if
if hiddenLayersAnswer is equal to "No" then
set thehiddenLayers to "No HiddenLayers"
end if
if hiddenLayersAnswer is equal to "Cancel" then
tell me to quit
end if
--theScriptFiles collects all the PSDs based on the user selection
set allFiles to do javascript file theScriptFiles with arguments {filesOrFoldersSelected}
--Once files are collected we already collect the LanguageCodes presented in the FilesName
set languageCodes to {}
set numberOfLanguages to my theSplit(allFiles, ",")
repeat with i from 1 to count of numberOfLanguages
set breakingThePath to my theSplit(item i of numberOfLanguages, "/")
set x to count of breakingThePath
set documentName to item x of breakingThePath
set theLanguageCode to my getTheLanguageCode(documentName, "_")
if theLanguageCode is in languageCodes then
else
set end of languageCodes to theLanguageCode
end if
end repeat
--theScriptArtboardFiles create seperate psd files from multiple artboard
set allFinalFiles to do javascript file theScriptArtboardFiles with arguments {allFiles}
--theScriptMain runs the bulk of the functionality (i.e. packaging)
do javascript file theScriptMain with arguments {answerMainDialog, theLabelAnswer, theRasterizeAnswer, thehiddenLayers, theRenameInput, outputLocationJS, allFiles, allFinalFiles}
end timeout
end tell
--Close all documents
tell application "Adobe Photoshop 2021"
activate
if countDocs is equal to 0 then
display dialog "Process Completed!" buttons {"OK"}
set the clipboard to {}
close every document saving no
else if wasRunning is equal to "True" then
display dialog "Finished." buttons {"OK"}
repeat with i from (count of documents) to countOfOpenDocs by -1
set theDocsDelimeter to i - 1 as number
do javascript "
var theDocsDelimeter = '" & theDocsDelimeter & "'
app.activeDocument = app.documents[theDocsDelimeter]
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES)
"
end repeat
end if
end tell
end if
on getTheLanguageCode(theString, theDelimiter)
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to theDelimiter
set theArray to every text item of theString
set AppleScript's text item delimiters to oldDelimiters
set languageCode to item 1 of theArray
return languageCode
end getTheLanguageCode
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
Copy link to clipboard
Copied
I don't know how much help this will be to you, I have next to no AS experience...
I couldn't get the alternative path syntax to work using colons : so swapping the : for /
Presuming that the path syntax is incorrect, I created a simple alert(); .jsx file on the desktop and the following works:
tell application "Adobe Photoshop 2021"
activate
set theScriptFile to "/Users/username/Desktop/alert.jsx"
do javascript of file theScriptFile
end tell
And here is the same with a slightly different syntax:
tell application "Adobe Photoshop 2021"
activate
set theScriptFile to ("/Users/username/Desktop/alert.jsx")
do javascript (file theScriptFile)
end tell
When I used this path syntax in your script for the .jsx files I didn't receive any errors and the script completed successfully.