clickData.func.sourcetab
gives you a Tab
object.
(You can find that out from the OnClick, ClickData and Func documentation.)
Look at the documentation for the Tab object to understand why your code wasn't working:
clickData.func.sourcetab.item.name
Tab objects do not have an item
property or method.
clickData.func.sourcetab.realpath.name
Tab objects do not have a realpath
property or method.
You can't use random property names on objects that aren't documented as supporting them.
Let's look at the part of the Default Script which demonstrates how to list the paths of all selected files and folders:
function OnClick(clickData)
{
// ...
for (var eSel = new Enumerator(clickData.func.sourcetab.selected); !eSel.atEnd(); eSel.moveNext())
{
if (eSel.item().is_dir)
{
DOpus.Output(" (d) " + eSel.item().realpath);
}
else
{
DOpus.Output(" (f) " + eSel.item().realpath);
}
}
// ...
}
We can simplify that, since we don't care about treating directories and files differently:
function OnClick(clickData)
{
for (var eSel = new Enumerator(clickData.func.sourcetab.selected); !eSel.atEnd(); eSel.moveNext())
{
DOpus.Output(eSel.item().realpath);
}
}
If you look at the documentation, clickData.func.sourcetab.selected
gives you a list of all selected items.
The for
loop in the Default Script takes that list and loops through each of those items. Unfortunately, JScript's syntax for enumerating a list is a little complex, but you can reuse the example in most situations.
Within that loop, eSel.item()
gets you an Item
object, one for each selected file or folder.
Look at the documentation for the Item object.
The Item
object has a name
property you can use to get just the filename. That's a shortcut, which gives you a quick way to get an item's name.
That is what Lxp was suggesting you use:
function OnClick(clickData)
{
for (var eSel = new Enumerator(clickData.func.sourcetab.selected); !eSel.atEnd(); eSel.moveNext())
{
DOpus.Output(eSel.item().name);
}
}
Lxp's suggestion is easier, but I'll explain my alternative suggestion as well, for completeness:
The Default Script gave you an example using eSel.item().realpath
which printed the full path to each item, and you wanted to modify that to print the names on their own.
Look at the documentation for the Item object again.
The Item
object's realpath
property is documented as returning a Path
object.
Look at the documentation for the Path object.
The Path
object has a filepart
property which returns just the name at the end of the path.
That is what I was suggesting you use:
function OnClick(clickData)
{
for (var eSel = new Enumerator(clickData.func.sourcetab.selected); !eSel.atEnd(); eSel.moveNext())
{
DOpus.Output(eSel.item().realpath.filepart);
}
}