Copy link to clipboard
Copied
What is the Javascript equivalent to this AppleScript?
set xxx to every page item whose note = "John"
After looking at some of the tutorials, I pieced this together. Is there a better way of doing this? With 30,000 path items it took over a minute to execute...
docRef = app.activeDocument;
var pathLength = docRef.pathItems.length;
docRef.pathItems[0].note;
var hitList = []
for (i = 0; i<pathLength; i++)
{
if (docRef.pathItems.note= "John")
{
hitList.push(i)
}
}
alert(hitList.length)
Copy link to clipboard
Copied
No better way I think, but shouldn’t it be if (docRef.pathItems.note == "John") ?
And if you only want to get length, there is no need for create an array, just increase the count is OK, maybe a little faster.
Copy link to clipboard
Copied
over a minute to process 30,000 items is awsome.
Copy link to clipboard
Copied
So like this?
docRef = app.activeDocument;
var pathLength = docRef.pathItems.length;
docRef.pathItems[0].note;
var myCount = 0
for (i = 0; i<pathLength; i++)
{
if (docRef.pathItems.note== "JD")
{
myCount = myCount + 1
}
}
alert(myCount)
Copy link to clipboard
Copied
myCount++ like you did with i