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

Ai Command Palette

Enthusiast ,
Jul 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

If you have worked with apps like Figma, Alfred, or VS Code you know how great the “command palette” is… Well, I wanted that same functionality in Adobe Illustrator so here's what I've come up with.

 

AiCommandPalette.png

 

What Can It Do:

  • most any Illustrator Menu command
  • any actions from your Actions Palette
  • scripts from anywhere on your filesystem
  • AND you can build custom commands that chain other commands together! 🤯

 

Installation:
I recommend installing this action into your scripts folder, then tying it to a keyboard shortcut using something like Keyboard Maestro (Mac), BetterTouchTool (Mac), or AutoHotkey (Windows).

 

:information: I like to use the keyboard shortcut Command-Shift-P since it is somewhat mnemonic for "palette".

 

Notes:
:warning: Using this command palette requires some basic knowledge of Illustrator. The script doesn't know which commands can or can't be run at the time of execution so tread carefully. Most every action this script executes can be undone by choosing Edit > Undo (from the Edit menu at the top of your screen), or by pressing Command-Z (Mac) or Control+Z (Windows).

 

:warning: MENU COMMANDS: I am aware that not all of the included built-in menu commands work. There are a little over 500 included in this script so I'm not interested in testing them all. If you find one that doesn't work, please file an issue in this repository (learn how here).

 

Credits:

  • Shalako Lee for the list of built-in menu commands and their respective executeMenuCommand() commands.
  • sttk3 for the awesome bit of code that gets all of the currently installed Action Sets and Actions.
  • Peter Kahrel and his amazing ScriptUI for Dummies book.
  • Sergey Osokin for the clever openURL() function.

 

It's far from perfect, but it's cool (at least to me). So, please check it out, take it for a spin, try to break it, and let me know what you think.

 

GitHub Download Link: https://github.com/joshbduncan/AiCommandPalette

YouTube Demo Video: https://www.youtube.com/watch?v=Jhh_Dvfs0ro

TOPICS
Scripting , Tools

Views

5.6K

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 3 Correct answers

Enthusiast , Aug 16, 2022 Aug 16, 2022

@colt-ink, thanks for the kind words and I'm glad you got your pref file sorted and everything is working fine now. Raycast is on my list of apps to check out, I'm just such a heavy user of Alfred (lots of custom workflows and scripts) that I'm not sure I would ever commit to making the switch. Alfred is the main reason I created Ai Command Palette, tbh...

 

I also wanted to let you know that I just released version 0.2.0 of Ai Command Palette if you want to check it out. It's got some new feature

...

Votes

Translate

Translate
Enthusiast , Sep 15, 2022 Sep 15, 2022

Ai Command Palette v0.3.0 has been released

Shoutout to @Sergey Osokin for his idea of the version check functionality and his help to develop a work-a-round for the Window OS Flicker/Flashing bug he described here.

 

As always, if anyone has issues or suggestions please reach out. Cheers :clinking_beer_mugs:

 

Read full CHANGLOG here.

 

Ai Version Functionality Checker:

  • Original idea brought up by Sergey Osokin in issue #6 selectTool
  • Ai Command Palette now checks the current Ai version at startup to det
...

Votes

Translate

Translate
Enthusiast , Oct 21, 2022 Oct 21, 2022

Ai Command Palette v0.4.0 has been released!

 

This is a complete rebuild of the script. Learn more here. Thanks again to @Sergey Osokin and @Kurt Gold for their continued help! :clinking_beer_mugs:

 

P.S. I'll try and get this updated in the near future once I can figure out the new tools that were added in the latest Ai 2023 27.0 release.

 

Added
- Real-Time Localization
- Handled within the main script file via the ExtendScript `localize()` function.
- Commands are built at run-time for the current sy

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

Thanks for providing that approach, jduncan.

 

I will try it next week.

 

Probably not really comparable, but it's a bit like Illustrator's native Discover panel (which is pretty new), right?

 

https://helpx.adobe.com/illustrator/using/illustrator-discover.html

 

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 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

Yeah, I'm not a big fan of the new discover/help panel (somewhat slow and the results can be blah). I'm a heavy user of the Alfred app on Mac so I wanted something similar that was super fast and efficient. I first built this to only access menu commands but then I realized I could chain them together which is a complete game changer (at least for me).

 

Thanks for checking it out!

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
Community Expert ,
Jul 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

jduncan this script is AMAZING!! what a great idea.

 

thanks for developing and sharing with the community!

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 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

@CarlosCanto, thanks for the kind words! And it's my pleasure to share. This was sort of a learning project for me and I'm pretty stoked about what I have so far. Still needs work for sure, but I'm enjoying using it daily.

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 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

It looks great. You take the trouble to move all the commands and think about the UI 👍

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
Contributor ,
Jul 30, 2022 Jul 30, 2022

Copy link to clipboard

Copied

Hi @jduncan 

How to run it? I put it in the script folder and executed it from the menu file > script , but it didn't show any prompts or windows....

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
Guide ,
Jul 30, 2022 Jul 30, 2022

Copy link to clipboard

Copied

@Raymond ZJH  You should be able to run it as any other script.  There is no special requirement. 

 

@jduncan  Very nice.  Thanks for sharing. 

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
Contributor ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

Hi @femkeblanco @jduncan 

 

I'm facing a major problem: The scripts don't get executed when clicking it from menu file > script, Nothing happens at all.

 

Do you perhaps have an idea what I may be overlooking?

 

script.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
Enthusiast ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

Yeah, that's weird. I haven't had anyone else report problems getting the script to run.

 

The only thing that really happens in the script before the palette pops up is the process of loading the user preference file (which you shouldn't even have it you can get the script to run). Can you try commenting out lines 78-80 and see if that helps? I have listed the lines below to make sure you get the right ones. To comment them out just put two backslashes at the start of the line like below.

 

// dataFolder = setupFolderObject(Folder.userData + "/" + "JBD");
// dataFile = setupFileObject(dataFolder, "AiCommandPalette.json");
// loadUserData(dataFile);

 

Give that a shot and let me know if you can at least get the palette to pop up?

 

You can also try running the script below that should just show the command palette for testing and alert you with the result. It's the same exact code from the main script, I just removed all of the extra processing that may be causing the problem.

 

sampleData = ["Some", "Sample", "Data", "For", "Testing"];
result = commandPalette(
  sampleData,
  "Test Command Palette Dialog",
  [0, 0, 500, 182],
  false,
  []
);
if (result) alert("Result\n" + result);

function commandPalette(arr, title, bounds, multiselect, filter) {
  var q, filteredArr, matches, temp;
  var cur = 0;

  var win = new Window("dialog");
  win.text = title;
  win.alignChildren = "fill";
  var q = win.add("edittext");
  q.helpTip = "Search for commands, actions, and loaded scripts.";
  q.active = true;

  if (filter.length > 0) {
    filteredArr = filterOutCommands(arr, filter);
  } else {
    filteredArr = arr;
  }

  var list = win.add("listbox", bounds, filteredArr, { multiselect: multiselect });
  list.selection = 0;

  // window buttons
  var winButtons = win.add("group");
  winButtons.orientation = "row";
  winButtons.alignChildren = ["center", "center"];
  var ok = winButtons.add("button", undefined, "OK");
  ok.preferredSize.width = 100;
  var cancel = winButtons.add("button", undefined, "Cancel");
  cancel.preferredSize.width = 100;

  // as a query is typed update the list box
  q.onChanging = function () {
    q = this.text;
    matches = q === "" ? filteredArr : scoreMatches(q, arr);
    if (matches.length > 0) {
      temp = win.add("listbox", list.bounds, matches, {
        multiselect: list.properties.multiselect,
      });
      // close window when double-clicking a selection
      temp.onDoubleClick = function () {
        if (list.selection) win.close(1);
      };
      win.remove(list);
      list = temp;
      list.selection = 0;
    }
  };

  if (!multiselect) {
    // move palette selection with arrow keys
    q.addEventListener("keydown", function (k) {
      if (k.keyName == "Up") {
        k.preventDefault();
        list.selection = list.selection.index - 1;
        if (cur > 0) {
          cur--;
        }
      } else if (k.keyName == "Down") {
        k.preventDefault();
        list.selection = list.selection.index + 1;
        if (cur < list.items.length) {
          cur++;
        }
      }
      // FIXME: check to see if palette also shows 9 rows on windows or offset reveal may be wrong
      // move the visible list item to keep selected item from jumping to top
      if (cur < 9) {
        list.revealItem(0);
      } else {
        list.revealItem(cur - 8);
      }
    });
  }

  // close window when double-clicking a selection
  list.onDoubleClick = function () {
    if (list.selection) win.close(1);
  };

  if (win.show() == 1) {
    if (list.selection) {
      return multiselect ? list.selection : [list.selection];
    }
  }
  return false;
}

/** score matching `arr` list items by count of matching words with `q` */
function scoreMatches(q, arr) {
  var score, word;
  var words = q.split(" ");
  var results = [];
  for (var i = 0; i < arr.length; i++) {
    score = 0;
    for (var n = 0; n < words.length; n++) {
      word = words[n].toLowerCase();
      if (word != "" && arr[i].toLowerCase().indexOf(word) >= 0) score++;
    }
    if (score > 0) results.push({ cmd: arr[i], score: score });
  }
  return sortResults(results, "score");
}

/** sort list `arr` objects in descending order by `key` */
function sortResults(arr, key) {
  var cur;
  var sortedResults = [];
  var sortedArr = [arr.shift()];
  while (arr.length >= 1) {
    cur = arr.shift();
    for (var i = 0; i < sortedArr.length; i++) {
      if (sortedArr[i][key] < cur[key]) break;
    }
    sortedArr.splice(i, 0, cur);
  }
  for (var i = 0; i < sortedArr.length; i++) {
    sortedResults.push(sortedArr[i]["cmd"]);
  }
  return sortedResults;
}

 

Let me know what you find out? Thanks!

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
Community Expert ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

perhaps it has something to do with the language? I see Chinese?

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 ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

Ah, good catch! I didn't even notice that. Yeah, I'm not really sure how languages can affect the script's ability and I don't really have a good way to test that. @Kurt Gold has been working to localize a German version and let me know of a few issues he was having but they were minor and definitely causing the script to even run.

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 ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

that guy downloaded a html file (1200KB) instead of js (97KB). That's how "Save link as " works on Github.

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 ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

Oh, well that makes sense. I noticed how much larger AiCommmandPalette.jsx was (in kb) than the other scripts they had loaded but I was on my phone and didn't think to check why. Good catch!

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
Contributor ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

Good eyesight 👍

 

You are right, it can't "Save link as " and now I use the copy command directly. 😊

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
Contributor ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

Yes, i'm in chinese Win10, good eyesight 😀

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
Contributor ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

Hi @jduncan 

First of all, I copied the code and saved it as a JS file. It is indeed 97kb. Thank @tomr11694738  for reminding. But it can't work, also nothing happens at all. The same as my previous screenshot.

RaymondZJH_0-1659679437599.png

 

I'll try to test it according to your method:

Commenting out lines 78-80:  

It can't work, also nothing happens at all. The same as my previous screenshot.

 

Run “show the command palette” code only, just like what you wrote above:

It can work! The palette pops up!

捕获.JPG

 

I don't know what went wrong. I use the Chinese Windows 10 system and have tried the Chinese version of AI (26.2.1) and the English version of AI (26.2.1). Both of them have the same problem.

 

Do you perhaps have an idea what I may be overlooking?

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 ,
Aug 05, 2022 Aug 05, 2022

Copy link to clipboard

Copied

It may be a language issue but you said you tried it in the English version of AI and still no luck... So I honestly don't know what could be the problem.

 

Let's try one last thing... Here's a link to the raw text of the script on GitHub. If you copied the script right off of the GitHub website it may have had some weird hidden characters or something that could cause issues.

 

When you visit the link above you can just do File > Save Page As, and save "AiCommandPalette.jsx" on your system. You can also do Edit > Select All, Edit > Copy, and then paste into a text editor if you prefer. Then try running that script and let me know if it 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
Contributor ,
Aug 05, 2022 Aug 05, 2022

Copy link to clipboard

Copied

Hi @jduncan 

 

Unfortunately, it doesn't work either with the "Save As" file. It can only run the script of the "main code" (just show the command palette). 😢😢

 

AP_test.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
Enthusiast ,
Aug 06, 2022 Aug 06, 2022

Copy link to clipboard

Copied

Did you try commenting out lines 78-80 like I mentioned on 8/1? That's really all I could see keeping it from running aside from language issues. I have listed the lines below to make sure you get the right ones. To comment them out just put two backslashes at the start of the line like below.

 
// dataFolder = setupFolderObject(Folder.userData + "/" + "JBD"); // dataFile = setupFileObject(dataFolder, "AiCommandPalette.json"); // loadUserData(dataFile);

 

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
Contributor ,
Aug 07, 2022 Aug 07, 2022

Copy link to clipboard

Copied

@jduncan 

 

Yes, i did it in the "AiCommandPalette_commenting78-80.js" file as my previous screenshot.

 

捕获.JPG

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 ,
Aug 08, 2022 Aug 08, 2022

Copy link to clipboard

Copied

To help figure out what part is breaking, I've linked below to two different stripped-down versions of the original script. Since the command palette is never showing on your system, something has to be breaking at the start of the script, and the script really only does a few things before presenting the palette. I suspect it may be the getAllActions() function so try running the two scripts linked below and let me know if either works.

 

The first excludes loading all of the menu commands...

Test Version #1 (Excluding Menu Commands)

 

The second excludes loading your built-in action...

Test Version #2 (Excluding Actions)

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
Contributor ,
Aug 08, 2022 Aug 08, 2022

Copy link to clipboard

Copied

Hi @jduncan 

 

The Version#1(Excluded Menu Options) can work, but the Version#2(Excluded Actions Options) didn't work.

 

RaymondZJH_0-1660006195452.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 ,
Aug 09, 2022 Aug 09, 2022

Copy link to clipboard

Copied

Yeah, I'd definitely say it's something to do with language then. There are about 500 built-in manu commands so it seems one or more of those is causing a problem.

 

If you wanted to hunt down the offending commands, you could comment out all of the commands at the bottom of the script and then start uncommenting batches of then to see if the script run. You should be able to determine the culprit(s). 

Also, maybe someone on this forum has some experience with the Chinese language and ExtendScript that could help us out.

 

Let me know if ?

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
Community Expert ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

Josh, I just posted a localised version of the Command palette for German versions of Illustrator.

 

You may want to take a look at it.

 

Command Palette – Localised version (German)

 

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