Skip to main content
Inspiring
May 30, 2021
Answered

Keyboard shortcut to execute specific function from script

  • May 30, 2021
  • 1 reply
  • 10794 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
Brainiac
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 30, 2021

Thank you! I will investigate your suggestion and let you know how it goes.

Brainiac
May 30, 2021

I use 5 separate script files that apply the same function to 5 separate Photoshop layers. 

Each script has its own keyboard combination key.

If the layer name is x then do function x.

 

I am trying to understand if it is possible to combine all 5 scripts into one main script and use separate keyboard shortcuts to execute a specific section of the main script. 

 

The Problem

Multiple script files

 

The solution 1

One script that responds to 5 separate  keyboard shortcuts

The solution 2

A loop that can detect the keyboard shortcut input and executes a function for the keyboard shortcut 

 

The benefit

One script file instead of 5 scripts 


Have you considered this option?