Copy link to clipboard
Copied
Just looking for confirmation: in CC does it appear that only recognized click even is a double-click?
but this will not trigger if the item is already selected.
if you want the list item to act as buttons then in the onChange you need to deselect the item.
...var w = new Window ("dialog");
var myList = w.add ("listbox");
myList.add ("item", "one");
myList.add ("item", "two");
myList.add ("item", "three");
myList.onChange = function(){
if(myList.selection != null){
alert('Item ' + myList.selection + ', "' + myList.selection.text + '" just got pressed');
myList.selection = null;
Copy link to clipboard
Copied
use .onChange
var w = new Window ("dialog");
var myList = w.add ("listbox");
myList.add ("item", "one");
myList.add ("item", "two");
myList.add ("item", "three");
myList.onChange = function(){alert('Item ' + myList.selection + ', "' + myList.selection.text + '" is currently selected');}
w.show ();
Copy link to clipboard
Copied
but this will not trigger if the item is already selected.
if you want the list item to act as buttons then in the onChange you need to deselect the item.
var w = new Window ("dialog");
var myList = w.add ("listbox");
myList.add ("item", "one");
myList.add ("item", "two");
myList.add ("item", "three");
myList.onChange = function(){
if(myList.selection != null){
alert('Item ' + myList.selection + ', "' + myList.selection.text + '" just got pressed');
myList.selection = null;
}
}
w.show ();
Copy link to clipboard
Copied
Never stop saving my tail sir!
Not in this Adobe world!
Copy link to clipboard
Copied
Always happy to help you, whenever I can... ![]()
Copy link to clipboard
Copied
Can you help me out in a theoretical matter?
I have a listbox, and onChange is fetching the current linklist and rebuilding the window.
While this i happening, the listbox looses its selection.
But If I want to select that item by ID I temproarely stored, the whole onChange-event fires again, putting me in a loop.
How can I select something from the listbox by script, while a onChange handler was installed, any ideas?
Copy link to clipboard
Copied
Can you elaborate more on your issue?
Copy link to clipboard
Copied
Yes, of course:
The issue is, that im not very skilled coding jsx, and got a whole bunch of the code from loic.aigon, but cant finish the script because I cant untangle the slick code. I made a few adjustments, like a progressbar and some string alterations, but these stacked eventhandlers give me the heebie jeebies, I cant understand nor solve.
What the script does, is throw a pallette with the linklist inside. The links are filtered by filepath matching strings from an array. When clicking on a item in the linkslist, the documentview jumps to the image, and the filename (without suffix) is copied to the clipboard.
The basic usecase should be to quickly find links not pointing to our DAM and exchanging them with an asset from the DAM (while the DAM plugin cant be scripted, the filename can only be pasted by hand. But that wraps up some redundant tasks in a script).
To test the script, you need a document with links point anywhere but const uris = ["srvmar16\.zentrale\.ad\.local","192\.168\.96\.116"]; e.g. like your desktop (you have to add that). If a filepath matches these values of the constant, its a "good" link, and is filtered from the listbox-linklist.
#targetengine 'temp1'
var ProgrammName = "DAM Check";
var myVersion = "0.2.180615"
var maxlinks, currentlinks,prevLinklistSelection;
app.scriptPreferences.enableRedraw = true;
prevLinklistSelection=-1;
function sortByKey(array, key) {
return array.sort(function(b, a) {
var x = a[key]; var y = b[key];
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
});
}
//Main routine
var main = function() {
var doc = app.properties.activeDocument,dlg, linksData, n,
callback;
if ( !doc ) return;
maxlinks = app.properties.activeDocument.links.everyItem().getElements().length;
currentlinks = ( getLinks().__count__ );
this.dlg = this.dlg || ui();
this.dlg.show();
}
//Retrieve doc links
function getLinks(){
const uris = [
"srvmar16\.zentrale\.ad\.local",
"192\.168\.96\.116","desktop"];
var ls, n = 0, l, o = {}, lid,
doc = app.properties.activeDocument, reg;
if ( !doc ) return o;
reg = new RegExp( "("+uris.join("|")+")", "i" );
ls = doc.links.everyItem().getElements();
n = ls.length; maxlinks = n;
sortByKey(ls, "name");
while ( n-- ) {
l = ls
; if ( reg.test( l.filePath) ) continue;
try {
Ort = l.parent.parentPage.name;
} catch(err) {Ort = "MF"};
lid = l.id;
o[lid] = {name:l.name, id:lid, container:l.parent.parent,onPage:Ort};
}
return o;
}
//UI build function
var ui = function (){
var u,
w = new Window('palette', ProgrammName+"["+$.engineName+"]"),
ls = w.add('listbox',undefined,undefined,{selection: prevLinklistSelection, numberOfColumns: 2, showHeaders: true, columnTitles: ["Seite", "Name"]}),
grp = w.add('group'),
pbar = grp.add ('progressbar', undefined, 0, maxlinks),
t1 = grp.add ('statictext', undefined, "999/999 ➜ 100 %"),
bgrp = w.add('group'),
btn1 = bgrp.add('button',u,"Über"),
btn2 = bgrp.add('button',u,"Schließen"),
//ttemp = w.add('statictext', undefined, "999"),
linkItem, listItem,
updateLinksList = function() {
var data, linkData, listItem;
//ttemp.text = ""+prevLinklistSelection;
ls.removeAll();
data = getLinks();
t1.text = ""+currentlinks+ "/"+maxlinks+" ➜ "+Math.round((100 - (((100 / maxlinks) * currentlinks))))+" %";
pbar.maxvalue = maxlinks;
pbar.value = maxlinks - currentlinks;
w.update();
if ( !data.__count__ ) return;
currentlinks = ( data.__count__ );
for ( prop in data ) {
linkData = data[prop];
listItem = ls.add('item', linkData.onPage);
listItem.subItems[0].text = linkData.name;
listItem.data = linkData;
};
}, ev = app.eventListeners.itemByName ( "onSelectionChanged" );
w.alignChildren = ["fill","fill"];
grp.alignChildren = ["fill","fill"];
bgrp.alignChildren = ["fill","fill"];
ls.preferredSize = [300,200];
ls.maximumSize.height = 300;
pbar.preferredSize = [400,2];
pbar.maxvalue = maxlinks;
pbar.value = maxlinks - currentlinks;
t1.characters = 16;
t1.justify = "right";
btn2.onClick = function(){w.close(0)};
btn1.onClick = function(){alert("work in progress")};
ls.onChange = function() {
if ( !ls.selection ) return;
prevLinklistSelection = ls.selection;
t1.text = ""+currentlinks+ "/"+maxlinks+" ➜ "+Math.round((100 - (((100 / maxlinks) * currentlinks))))+" %";
zoomObject ( ls.selection.data.container );
SetClipboard ( ls.selection.data.name.replace ( /\.[a-z]+$/i, '') );
}
w.onShow = function(){
updateLinksList();
}
if ( !ev.isValid ) {
app.eventListeners.add("afterSelectionChanged",function(evt){
updateLinksList();
t1.text = ""+currentlinks+ "/"+maxlinks+" ➜ "+Math.round((100 - (((100 / maxlinks) * currentlinks))))+" %";
pbar.maxvalue = maxlinks;
pbar.value = maxlinks - currentlinks;
});
}
return w;
};
//Created by Dave Saunders > http://jsid.blogspot.fr/2006/01/zoom-in-on-object.html
function zoomObject(theObj) {
try {
var objBounds = theObj.geometricBounds;
} catch (e) {
throw "Objekt hat keine Abmessungen."
}
var ObjHeight = objBounds[2] - objBounds[0];
var ObjWidth = objBounds[3] - objBounds[1];
var myWindow = app.activeWindow;
var pageBounds = myWindow.activePage.bounds;
var PgeHeight = pageBounds[2] - pageBounds[0];
var PgeWidth = pageBounds[3] - pageBounds[1];
var hRatio = PgeHeight/ObjHeight;
var wRatio = PgeWidth/ObjWidth;
var zoomRatio = Math.min(hRatio, wRatio);
app.select(theObj); // to make active the page that holds theObj
myWindow.zoom(ZoomOptions.fitPage);
myWindow.zoomPercentage = myWindow.zoomPercentage; // * zoomRatio;
}
//See here for reference :
//https://forums.adobe.com/thread/2203330
function SetClipboard(clip){
var clipboard;
if(File.fs == "Macintosh"){
app.doScript ('tell application "Finder" to set the clipboard to "'+clip+'"',ScriptLanguage.APPLESCRIPT_LANGUAGE);
} else {
app.doScript ( 'Dim theObject\r Set theObject = CreateObject (\"htmlfile\")\r Call theObject.ParentWindow.ClipboardData.SetData(\"text\",\"'+clip+'\")', ScriptLanguage.visualBasic );
}
return;
}
main();
Copy link to clipboard
Copied
It is an InDesign script, so the various event-handling procedures for InDesign may not be available in Illustrator, such as things like 'ev = app.eventListeners.itemByName ( "onSelectionChanged" );' . I suggest that you try to ask it on the InDesign Scripting forum and try your luck there.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more