Dear All
I have a script that unlocks all layers in layer sets and then plays an action. However, it is slow on files that have many layers and layer sets. Does anyone have a quick solution to my problem.
Here’s the script, it should work on CS4 as well if you change the name.
on open thefiles
tell application "Adobe Photoshop CS5.1"
activate
repeat with thisfile in thefiles
open thisfile
--create a variable named theDocRef
--assign the current (active) document to it
set theDocRef to the current document
tell theDocRef
my unlockLayers(layers)
end tell
do action "Full clean 150dpi No Save" from "Clean up files"
tell theDocRef
save
close
end tell
end repeat
end tell
end open
-- loops through all subsets by running the script again if a layer set is found
on unlockLayers(myCurrentLayers)
tell application "Adobe Photoshop CS5.1"
repeat with i from 1 to count myCurrentLayers
set mylayer to item i of myCurrentLayers
if class of mylayer is art layer then
set all locked of mylayer to false
else if class of mylayer is layer set then
set all locked of mylayer to false
my unlockLayers(layers of mylayer)
end if
end repeat
end tell
end unlockLayers
Model: 2 x 2.8 GHz Quad-Core Intel Xeon
AppleScript: 2.1.2
Browser: Firefox 3.6.14
Operating System: Mac OS X (10.6)
Hi,
you could use the “whose” statement, but if this would be faster¿
--old fashioned CS
tell application "Adobe Photoshop CS"
tell current document
try
set all locked of (every art layer whose all locked is true) to false
end try
try
set all locked of (every art layer of every layer set whose all locked is true) to false
end try
try
set all locked of (every art layer of every layer set of layer sets whose all locked is true) to false
end try
try
set all locked of (every layer set of layer sets whose all locked is true) to false
end try
try
set all locked of (every layer set whose all locked is true) to false
end try
end tell
end tell
Thanks Hans for your help
In the end I did more or less what you suggested. I have re-organised it slightly to run the layer sets first (it’s faster that way). This new version does not drill into all possible layer sets, but it is a lot faster than looping through everything.
If anyone has any other ideas, I would still be interested.
Here’s my final code. Note that only unlockLayers2 is being used.
-- this script unlocks layers and then runs an action that assigns the correct profile, deletes hidden layers, crops of extra stuff, and reduces the resolution to 150ppi
-- if there are hidden and locked layers more than four deep the action will stop until stop or continue is pressed
on run
tell application "Adobe Photoshop CS5.1"
activate
set theDocRef to the current document
tell theDocRef
my unlockLayers2(layers)
end tell
do action "Full clean 150dpi No Save" from "Clean up files"
tell theDocRef
save
close
end tell
end tell
end run
on open thefiles
tell application "Adobe Photoshop CS5.1"
activate
repeat with thisfile in thefiles
open thisfile
--create a variable named theDocRef
--assign the current (active) document to it
set theDocRef to the current document
tell theDocRef
my unlockLayers2(layers)
end tell
do action "Full clean 150dpi No Save" from "Clean up files"
tell theDocRef
save
close
end tell
end repeat
end tell
end open
-- loops through all subsets by running the script again if a layer set is found
-- it's slow, hence version 2 of the handler is being used in this script
on unlockLayers(myCurrentLayers)
tell application "Adobe Photoshop CS5.1"
repeat with i from 1 to count myCurrentLayers
set mylayer to item i of myCurrentLayers
if class of mylayer is art layer then
if all locked of mylayer is true then -- otherwise hidden layers will be made visible
set all locked of mylayer to false
end if
else if class of mylayer is layer set then
if all locked of mylayer is true then -- otherwise hidden layer sets will be made visible
set all locked of mylayer to false
end if
my unlockLayers(layers of mylayer)
end if
end repeat
end tell
end unlockLayers
-- this handler will drill down into three levels of layer sets and their contents
on unlockLayers2(myCurrentLayers)
tell application "Adobe Photoshop CS5.1"
tell current document
-- unlock first level of layer sets
try
set all locked of (every layer set whose all locked is true) to false
end try
-- unlock second level of layer sets
try
set all locked of (every layer set of layer sets whose all locked is true) to false
end try
-- unlock third level of layer sets
try
set all locked of (every layer set of layer sets of layer sets whose all locked is true) to false
end try
-- unlock first level of layers
try
set all locked of (every art layer whose all locked is true) to false
end try
-- unlock second level of layers
try
set all locked of (every art layer of every layer set whose all locked is true) to false
end try
-- unlock third level of layers
try
set all locked of (every art layer of every layer set of layer sets whose all locked is true) to false
end try
-- unlock fourth level of layers
try
set all locked of (every art layer of every layer set of layer sets of layer sets whose all locked is true) to false
end try
end tell
end tell
end unlockLayers2