Copy link to clipboard
Copied
Hi,I have experience as programmer but not in applescript or photoshop scritpting,
Basically I want to apply some actions to layers, but only to those layers that are named ending in '-changeMe' e.g ( 'Layer 1-changeMe', 'Background-changeMe')
I'm trying to convert the pseudocode below to applescript
foreach layer in CurrentDocument.layers
if layer.name contains '-changeMe'
do something
end if
end foreach
In the pseudocode above I'm inveting the notation, but I hoppe you get the idea.
it's posible?
Thanks!
Thanks guys for the help, I finally manage to mix applescript and javascript, simply awesome.
--target Photoshop CS6
tell application "Adobe Photoshop CS6"
do javascript "
var theLayers = app.activeDocument.layers;
var LayersName, result;
var searchString = /[-]changeMe/;
for (i=0; i<theLayers.length; i++) {
LayersName = theLayers.name;
result = LayersName.search(searchString);
if (result != -1) {
alert('Found in layer: '+LayersName);
// or do something else
}
}
...
Copy link to clipboard
Copied
Would you be willing to use JavaScript instead?
I think at least one of the regulars in this Forum is AppleScript savvy, but most people seem to avoid it for Photoshop Scripting purposes.
Copy link to clipboard
Copied
Yes, I love javascript, but I'm wondering if it's posible to launch javascript actions from actionscript. Because I want to have some actions integrated at the OS level, to have the posibility for example to right click on a folder or file and launch the script from there, passing the folder path or file as an argument.
Not sure if I can call javascript from applescript.
Apart of that I'm intresting to see javascript solutions to the same problem, I may still change my mind while practicing.
Copy link to clipboard
Copied
Yes you can call any JavaScript syntax including Action Manager syntax from AppleScript… You pass the command a string or file to the JS and it also takes arguments…
Copy link to clipboard
Copied
I can't help you with AppleScript.
But this JavaScript works.
// FindStringInLayersName.jsx
// http://forums.adobe.com/thread/1227665?tstart=0
// find layers which have "-changeMe" in the name
var theLayers = app.activeDocument.layers;
var LayersName, result;
var searchString = /[-]changeMe/;
for (i=0; i<theLayers.length; i++) {
LayersName = theLayers.name;
result = LayersName.search(searchString);
if (result != -1) {
alert("Found in layer: "+LayersName);
// or do something else
}
}
Perhaps someone else can translate this.
Good luck
Copy link to clipboard
Copied
Thanks guys for the help, I finally manage to mix applescript and javascript, simply awesome.
--target Photoshop CS6
tell application "Adobe Photoshop CS6"
do javascript "
var theLayers = app.activeDocument.layers;
var LayersName, result;
var searchString = /[-]changeMe/;
for (i=0; i<theLayers.length; i++) {
LayersName = theLayers.name;
result = LayersName.search(searchString);
if (result != -1) {
alert('Found in layer: '+LayersName);
// or do something else
}
}
"
end tell
Find more inspiration, events, and resources on the new Adobe Community
Explore Now