Skip to main content
Inspiring
May 30, 2021
Answered

Keyboard shortcut to execute specific function from script

  • May 30, 2021
  • 1 reply
  • 10825 views

I work with custom Photoshop scripts and keyboard shortcuts.

Is it possible to have a keyboard shortcut execute a specific function within a script?

and, another keyboard shortcut executes another function in the same script?

 

For example?

Citrus.jsx

  • function pomelos(){}
  • function lemons(){}
  • function oranges(){}

 

Keyboard F1 executes the function Pomelos

Keyboard F2 executes the function Lemons

Keyboard F3 executes the function Oranges

 

 

 

This topic has been closed for replies.
Correct answer r-bin

Got it, I realized it is possible to add more than one keyboard shortcut per script in Photoshop.

Each function key alerts the function key number followed by Error 21.

 

The Adobe UXP is the new Unified Extensibility Platform to build panels.

To make it user-friendly the button panel should stay docked to make it accessible.


[Profanity removed]

Remove the first test alert() and refresh() from the script.

1 reply

Kukurykus
Legend
May 30, 2021

Assiang F1 key to the script, basicly for pomelos function. When you want to trigger lemons then during refreshment change your finger from F1 key to F2. Similary if you want to initiate oranges, switch to F3.

 

refresh()

function pomelos() {alert(callee.name)}
function lemons() {alert(callee.name)}
function oranges() {alert(callee.name)}

({1: pomelos, 2: lemons, 3: oranges})[ScriptUI.environment.keyboardState.keyName[1]]()

 

Inspiring
May 31, 2021

I try the citrus.jsx script in Photoshop CC 2021 and get error 21 when I press the F1 key in a mac.

Then I get several erro 24 dialogs when I press F1 ket for one sec and then switch to F2 key.

What do these errors mean?

 

 

Kukurykus
Legend
June 1, 2021

This also raises "undefined is not an object". I have it for sure.

If you looked at the code with "buttons", then they do not have to be pressed.

Buttons can be removed or hidden altogether, as well as the dialog itself, if it is unpleasant for the user.

It is enough to press the desired keys.

 

By the way, multiple hotkeys can be assigned to tools as well. But this is a bit tricky. 🙂

 


I'm not having 'undefined is not an object'. I tried to reproduce it and I couldn't even once.

 

Hidden buttons with shortcuts could be alternative of course, but that you showed, so more keys assigned to same functionality is much better option. Surely I would use it with no doubt.

 

I always had same hotkey assigned for some Tools, but to switch them you must press that key with Shift, and I don't see option like for App Menus to add more hotkeys for the same tool.