Copy link to clipboard
Copied
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
Keyboard F1 executes the function Pomelos
Keyboard F2 executes the function Lemons
Keyboard F3 executes the function Oranges
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]]()
[Profanity removed]
Remove the first test alert() and refresh() from the script.
Copy link to clipboard
Copied
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]]()
Copy link to clipboard
Copied
It seems to me that there should be an endless loop. Not?
Also swears at the line:
({1: pomelos, 2: lemons, 3: oranges})[ScriptUI.environment.keyboardState.keyName[1]]()
undefined is not an object
upd.
keyName == undefined
upd2.
Copy link to clipboard
Copied
Basicly save script to Presets / Scripts, relaunch Photoshop and assign F1 to appropriate item from File / Scripts. Then press F1 (for one second, that's the time of refresh()) so the script is going to call pomelos function. If you press F1 and then switch your finger to F2 or F3 for the time of lasting second it is going to call lemons or oranges.
I used it for some project and never had endless loop, and can't say why it could be unreliable if it always worked for me. To avoid one second of waiting after pressing the function key, you can combine it with BridgeTalk.
Copy link to clipboard
Copied
Yes I understand. It is not comfortable. I can not. And it must be remembered that you need to keep the key (even F1) pressed for a while.
Copy link to clipboard
Copied
Implementing BridgeTalk shortens time of awaiting for the result to milliseconds.
Copy link to clipboard
Copied
Don't you consider the option with several hotkeys?
Copy link to clipboard
Copied
Personally I used it fundamentally as F1 (for main part of script), also together with Shift, Alt or Ctrl for special options, or else combinations of them, when holding more keys beside F1.
Copy link to clipboard
Copied
Thank you! I will investigate your suggestion and let you know how it goes.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Have you considered this option?
Copy link to clipboard
Copied
Does it require building a UXP Photoshop panel?
And how would each button link to a specific function within the script?
Similar to assigning a unique ID to the button and the function to trigger the function?
Copy link to clipboard
Copied
Does it require building a UXP Photoshop panel?
And how would each button link to a specific function within the script?
Similar to assigning a unique ID to the button and the function to trigger the function?
By @Polycontrast
var f = null;
var d = new Window("dialog")
d.orientation = "row";
d.b1 = d.add("button", undefined, "Func1");
d.b2 = d.add("button", undefined, "Func2");
d.b3 = d.add("button", undefined, "Func3");
d.b4 = d.add("button", undefined, "Func4");
d.b5 = d.add("button", undefined, "Func5");
d.b1.onClick = function() { f = func1; d.close(); }
d.b2.onClick = function() { f = func2; d.close(); }
d.b3.onClick = function() { f = func3; d.close(); }
d.b4.onClick = function() { f = func4; d.close(); }
d.b5.onClick = function() { f = func5; d.close(); }
d.addEventListener("keydown", key_handle, false);
d.b1.active = true; // otherwise a glitch
d.show()
if (f) f();
function key_handle(e)
{
switch (e.keyName)
{
case "F1": d.b1.notify(); break;
case "F2": d.b2.notify(); break;
case "F3": d.b3.notify(); break;
case "F4": d.b4.notify(); break;
case "F5": d.b5.notify(); break;
}
}
function func1() { alert(1); }
function func2() { alert(2); }
function func3() { alert(3); }
function func4() { alert(4); }
function func5() { alert(5); }
Copy link to clipboard
Copied
He asked for shortcuts, not buttons 😉
Copy link to clipboard
Copied
Thank you for the suggestion. The button panel would work best if the panel is a floating or dockable panel. I believe this can be done with a UXP panel. Is possible to assign a keyboard shortcut to a UXPl panel button?
This way the function can be triggered through the UI button or keyboard shortcut.
Copy link to clipboard
Copied
To Polycontrast
You know more than me. Why don't you try it yourself? What is "UXP panel"?
Copy link to clipboard
Copied
UXP is something more experienced than that I think you didn't like, so CEP.
Copy link to clipboard
Copied
You already explained in first post what you wish, and you got appropriate script. It does that you want, so what is problem? Did you even try it? That does exactly you are describing now.
Copy link to clipboard
Copied
I have not to try yet, first, I must interpret it to figure out of to apply your suggestion. It is not a simple process for me. Once I try it I can share my findings.
Copy link to clipboard
Copied
Hmm, the script is finished, just replace content of functions for yours.
But before you replace anything inside, just run it to see how it works...
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Insert into your script in the first line
alert (ScriptUI.environment.keyboardState.keyName)
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Why don't you like my script? The keys f1-f5 also work there.
You can also assign the same f1 key to the script call.
There is no need to do any special delays or tricks with your fingers.