• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Display opened windows in a panel as a buttons

Participant ,
Jul 18, 2024 Jul 18, 2024

Copy link to clipboard

Copied

Hi, can anyone help with a script which can display these opened windows in illustrator in a panel with each document as a button.

It will help in doing back and forth with ease by clicking those buttons.

 

My working involves opening of lot of files and navigating them get difficult when I have lot of files opened.

 

StarAG_1-1721289562126.png

 

TOPICS
Feature request , Scripting

Views

775

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jul 18, 2024 Jul 18, 2024

I would generally use a resizable list box with a scroll. Because if there are more documents open than the height of the monitor, the interface with buttons will be cut off. Technical limitations of Illustrator.

 

On macOS with the "palette" type interface, Adobe has a bug that causes the script interface to move behind the Illustrator window on every click in the document.  This bug does not exist on PC. Mac users should run the script from the File > Scripts menu to avoid this bug.

 

 

/*
  Docume
...

Votes

Translate

Translate
Adobe
Enthusiast ,
Jul 18, 2024 Jul 18, 2024

Copy link to clipboard

Copied

Try this. After each document activation, Illustrator reorders the array of open documents so that all open documents are added to the array first. Long filenames shortened to 20 characters.

Warning: This version does not work on PCs. The problem is solved in the second version of the script

 

#target illustrator
#targetengine docSwitcher

// Save the current order because after activating doc all array reordered
var docs = get(app.documents);

function main () {
  var win = new Window("palette", "Document Switcher");
      win.preferredSize.width = 200;
      win.spacing = 20;
      win.alignChildren = "fill";

  var docsGrp = win.add("group");
      docsGrp.orientation = "column";
      docsGrp.alignChildren = "fill";

  for (var i = 0; i < docs.length; i++) {
    addButton(docsGrp, docs[i].name, i);
  }

  var btnClose = win.add("button", undefined, "Close");

  for (var j = 0; j < docsGrp.children.length; j++) {
    docsGrp.children[j].onClick = function () {
      sendMessage(this.properties.idx);
      this.active = true;
      this.active = false;
    }
  }

  btnClose.onClick = function () {
    win.close();
  }

  win.center();
  win.show();
}

// Convert collection into standard Array
function get(coll) {
  var out = [];
  for (var i = 0, len = coll.length; i < len; i++) {
    out.push(coll[i]);
  }
  return out;
}

// Generate buttons
function addButton(target, name, idx) {
  if (name.length > 20) name = name.slice(0, 20) + '...';
  var btn = target.add("button", undefined, name.slice(), { idx: idx });
  return btn;
}

function sendMessage(idx) {
  var bt = new BridgeTalk();
  bt.target = BridgeTalk.appSpecifier;
  var msg = switchDoc +  "\rswitchDoc(" + idx.toSource() + ");";
  bt.body = msg;
  bt.send();
}

function switchDoc(idx) {
  app.activeDocument = docs[idx];
}

// Run script
try {
  main();
} catch (e) {}

 

SergeyOsokin_0-1721372251354.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 18, 2024 Jul 18, 2024

Copy link to clipboard

Copied

Hi, thanks for the script.

 

It does displays them in a list with doc name but navigation and clicking do not work.

 

Also, is it possible to:

1- reduce the button size to 50-70%

2- on mouse hover, it displays full name

3- display in 2 columns

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 18, 2024 Jul 18, 2024

Copy link to clipboard

Copied

 

quote

It does displays them in a list with doc name but navigation and clicking do not work.

 

What operating system? What version of Illustrator? On Mac OS buttons works.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 18, 2024 Jul 18, 2024

Copy link to clipboard

Copied

Windows 10 pro

StarAG_0-1721371898139.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 18, 2024 Jul 18, 2024

Copy link to clipboard

Copied

I would generally use a resizable list box with a scroll. Because if there are more documents open than the height of the monitor, the interface with buttons will be cut off. Technical limitations of Illustrator.

 

On macOS with the "palette" type interface, Adobe has a bug that causes the script interface to move behind the Illustrator window on every click in the document.  This bug does not exist on PC. Mac users should run the script from the File > Scripts menu to avoid this bug.

 

 

/*
  DocumentSwitcher.jsx for Adobe Illustrator
  Description: Displays a list of currently open documents and allows you to activate any document with a single click.
  Discussion: https://community.adobe.com/t5/illustrator-discussions/display-opened-windows-in-a-panel-as-a-buttons/td-p/14745128
  Date: July, 2024
  Author: Sergey Osokin, https://github.com/creold

  FOR MAC OS: Run the script from File > Scripts. This avoids the z-ordering problem of the script window.
*/

#target illustrator
#targetengine docSwitcher

(function () {
  // Save the current order because after activating doc all array reordered
  var docs = getDocsInfo();

  var win = new Window("palette", "Document Switcher", undefined, {resizeable: true});
  win.preferredSize.width = 200;
  win.spacing = 20;
  win.alignChildren = ["fill", "fill"];

  var listbox = win.add("listbox", undefined, undefined,
    {
      numberOfColumns: 2,
      showHeaders: true,
      columnTitles: ["#", "Document Name"],
      multiselect: false
    });

  addList(docs);

  var btnClose = win.add("button", undefined, "Close");
  btnClose.alignment = ["center", "bottom"];

  listbox.onChange = function () {
    selectListItem(docs);
  }

  btnClose.onClick = function () {
    win.close();
  }

  win.onResizing = function () {
    this.layout.resize();
  }

  win.onActivate = function () {
    if (listbox.children.length !== app.documents.length) {
      sendDocumentList();
    }
  }

  // Add opened documents list
  function addList(arr) {
    listbox.removeAll();

    for (var i = 0; i < arr.length; i++) {
      var row = listbox.add("item", i + 1);
      row.subItems[0].text = arr[i].name;
    }
  }

  // Select list items and zoom to them contents
  function selectListItem(arr) {
    for (var i = 0; i < listbox.children.length; i++) {
      if (listbox.children[i].selected) {
        sendMessage(arr[i].path, arr[i].name);
      }
    }
  }

  function sendDocumentList() {
      var bt = new BridgeTalk();
      bt.target = BridgeTalk.appSpecifier;

      var msg = getDocsInfo + "\rgetDocsInfo().toSource()";
      bt.body = msg;

      bt.onResult = function(result) {
        docs = eval(result.body);
        addList(docs);
      };

      bt.send();
  }

  // Get documents info
  function getDocsInfo() {
    var arr = [];
    for (var i = 0; i < app.documents.length; i++) {
      arr.push({
        name: app.documents[i].name,
        path: app.documents[i].fullName
      });
    }
    return arr;
  }

  function sendMessage(docPath, docName) {
    var bt = new BridgeTalk();
    bt.target = BridgeTalk.appSpecifier;
    var msg = switchDoc + "\rswitchDoc(" + docPath.toSource() + "," + docName.toSource() + ");";
    bt.body = msg;
    bt.send();
  }

  function switchDoc(docPath, docName) {
    var f = new File(docPath);
    if (f.exists) {
      app.open(new File(docPath));
    } else {
      app.documents[docName].activate();
    }
  }

  win.center();
  win.show();
})();

 

SergeyOsokin_0-1721371933103.png

Upd 1: Dialog is now resizable. Fixed for PC

Upd 2: After opening or closing documents, the panel updates the list

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 18, 2024 Jul 18, 2024

Copy link to clipboard

Copied

Listbox with scroll is ok.. can you make the panel frame resizable?

 

Further, I again checked this new script and it doesn't navigate and do nothing even after clicking.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 19, 2024 Jul 19, 2024

Copy link to clipboard

Copied

Try the last updated script

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 19, 2024 Jul 19, 2024

Copy link to clipboard

Copied

Works fine.. thanks a lot.

Though resizing is bit laggy, but it can be managed. Thanks for quick resolution. 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 19, 2024 Jul 19, 2024

Copy link to clipboard

Copied

A small issue I am seeing is that, say if 10 documents are opened then the panel will display 10 in the list.

But when I open few more documents then the list do not updates, it still displays only 10 docs.

 

Also, is it possible to scroll and move the documents up and down in the panel resulting scrolling of opened files.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 19, 2024 Jul 19, 2024

Copy link to clipboard

Copied

quote

Also, is it possible to scroll and move the documents up and down in the panel resulting scrolling of opened files.

These requests are not within the scope of the dialog script capabilities.

 

In the updated post above, check the dynamic document list. It works like this: when you activate the script window, it checks the length of the list and the number of open documents, if they don't match, it rebuilds the list.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 24, 2024 Jul 24, 2024

Copy link to clipboard

Copied

This works.

The only issue I am seeing is, when there is any change in the document list, it does update but it takes time of some seconds and is not instantaneous...

As it take times the same panel becomes unresponsive and working flow slows with other tasks within illustrator.

 

Can this be instant?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 24, 2024 Jul 24, 2024

Copy link to clipboard

Copied

It can't be instantaneous. It is a tortuous path of collecting and sending current data between Adobe Illustrator and the script palette via the BridgeTalk module.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 24, 2024 Jul 24, 2024

Copy link to clipboard

Copied

oh, in that case, can you please revert or share the copy of the previous script without auto-update option.

I have to frequently open and close tabs and this delay is causing workflow slowdown and software unresponsiveness.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 24, 2024 Jul 24, 2024

Copy link to clipboard

Copied

The "palette" window type in scripts with BridgeTalk always has a number of side issues. This is the price of always running it on top of Illustrator. But why not create a script with a modal dialog that can be launched as needed with a hotkey to switch documents and close them. The modal script will gather actual information about open documents at the moment it is launched.

 

The unexplained reason for both versions of the script is that on a PC (Windows), the script that collects information about open documents runs for 2 seconds. On Mac OS it starts immediately.

 

DocumentSwitcher-modal.gif

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 24, 2024 Jul 24, 2024

Copy link to clipboard

Copied

Modal dialog would be better for this. Panels in Ai made with scripts are really not worth it.

Modals launch faster and there is no real need (at least for me) to see the list of opened docs all the time (given the fact we can’t disable tabs really). So I’d assign it to a hotkey (actions will work with a modal script as wel properly), and call it only when I need to see/find the docs.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 04, 2024 Oct 04, 2024

Copy link to clipboard

Copied

LATEST

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines