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

Keyboard shortcut to execute specific function from script

Engaged ,
May 30, 2021 May 30, 2021

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

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

 

Keyboard F1 executes the function Pomelos

Keyboard F2 executes the function Lemons

Keyboard F3 executes the function Oranges

 

 

 

TOPICS
Actions and scripting

Views

7.2K

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

LEGEND , May 30, 2021 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]]()

 

Votes

Translate

Translate
People's Champ , May 31, 2021 May 31, 2021

[Profanity removed]

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

Votes

Translate

Translate
Adobe
People's Champ ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

Also, you did not say how you feel about this option.
bbb.png
 
You already know how to detect the key that called the script (first line of code)

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 ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

Thank you, I do like the button panel script! I think it will work well with a UXP panel that stays open and does not close on button press. 

 

In general, I try to avoid panels because interacting with a panel takes longer than executing a keyboard shortcut. Ideally, it would be useful to have both options. To trigger a specif script function through a panel button and alternatively trigger the panel button from a keyboard shortcut.

 

A question, how are you able to assign 3 separate shortcuts (F1, F2, F3) to the Layers to Files... script in your system? My system only allows one shortcut per 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
People's Champ ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

Do you have an "Add Shortcut" button? Show a screenshot of the hotkey settings dialog.

 

PS. What is UXP panel? I already hear from you for the second time.

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 ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

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.

Screen Shot 2021-05-31 at 3.07.22 PM.pngScreen Shot 2021-05-31 at 3.11.54 PM.png

 

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.

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
People's Champ ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

[Profanity removed]

Remove the first test alert() and refresh() from the 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
People's Champ ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

quote

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.


By @Polycontrast

 

Can you provide a sample code for such a panel? How does it work, how does it run? Are they text files like jsx 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
Engaged ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

Awesome! Thank you all. I am able to call specific functions within the same script using separate keyboard shortcuts in a mac osx without errors.

F1 calls the function pomelos

F2 calls the function lemons

F3 calls the function  oranges

 

I don't have any code to share about UXP panels since I am just learning about this new framework and have not built a plugin yet. However, I can share a link that covers how to get started UXP for Adobe Photoshop

 

 

Screen Shot 2021-05-31 at 3.54.59 PM.pngScreen Shot 2021-05-31 at 3.55.02 PM.pngScreen Shot 2021-05-31 at 3.55.06 PM.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
LEGEND ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

Loll, you selected wrong answer as correct 😉

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
LEGEND ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

I agree, I don't like buttons. When I can I personally use shortcuts.

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
LEGEND ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

I didn't know too you can assign more hotkeys to same script 😉 btw you said that before, but I thought you say about using other keys than function keys when using 'keyboardState': And, if you remember, you can assign any number of hotkeys to the script, then everything's easier.

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
LEGEND ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

Loll, you don't read my answers, I told you twice you can combine code with BridgeTalk. Then you don't have to hold a key for a second, but 200 times less, that is enough time to release main key and press other key within this time. When you keep your second finger over F1, and next one on F2 and F3, it's not any trick to use them smootly:

 

if ($.engineName)
	((bt = new BridgeTalk()).target = BridgeTalk.appSpecifier,
	(bt.body = '$.evalFile(' + $.fileName.toSource() + ')', bt.send()))
else{
	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]]()
}

 

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
People's Champ ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

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. 🙂

 

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
LEGEND ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

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.

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
People's Champ ,
Jun 01, 2021 Jun 01, 2021

Copy link to clipboard

Copied

quote

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.


By @Kukurykus

 

Examine the files "Keyboard Shortcuts Primary.psp" and "Keyboard Shortcuts.psp".

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
LEGEND ,
Jun 01, 2021 Jun 01, 2021

Copy link to clipboard

Copied

There's no 'Keyboard Shortcuts Primary.psp' in 'Adobe Photoshop 2021 Settings', and I'm not sure if I ever saw it there. In 'Keyboard Shortcuts.psp' I see for example this:

 

<tool name="Rectangular Marquee Tool" type="1" key="1919380852">M</tool>
<tool name="Elliptical Marquee Tool" type="1" key="1701604724">M</tool>

 

but I still have to use M key with shift to choose that secong tool, so what do you mean?

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 ,
Jun 05, 2021 Jun 05, 2021

Copy link to clipboard

Copied

The BridgeTalk code work in mac but not smoothly. The function key needs to be held down for a few milliseconds before the alert pops up. The last code snippet works better because there is no delay. Press the function key and the alert pops up immediately.

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
LEGEND ,
Jun 05, 2021 Jun 05, 2021

Copy link to clipboard

Copied

Thank you. That I needed to know. There's a little delay but it's bettter than entire second 😉

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
LEGEND ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

Did you read content of given link, why F1 and F2 may not work in Photoshop on Mac?

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 ,
Jan 09, 2022 Jan 09, 2022

Copy link to clipboard

Copied

Hi, can you please help figuerout how to modify the script to use a a different set of keyobrd keys.

Is it possible for example to use this type of keybord squence? 

F3+command for pomelos function

F6+command+opton for lemons function

F7+command+option+shift for oranges function

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
LEGEND ,
Jan 09, 2022 Jan 09, 2022

Copy link to clipboard

Copied

Assign script to F3, then within second switch to appropriate combination, or hold instead:

 

refresh()

function pomelos() {kS.ctrlKey && alert(callee.name)}
function lemons() {kS.ctrlKey && kS.altKey && alert(callee.name)}
function oranges() {kS.ctrlKey && kS.altKey && kS.shiftKey && alert(callee.name)}

(kN = (kS = ScriptUI.environment.keyboardState).keyName) &&
/[367]/.test(_ = kN[1]) && ({3: pomelos, 6: lemons, 7: oranges})[_]()

 

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 ,
Jan 09, 2022 Jan 09, 2022

Copy link to clipboard

Copied

Thank you, I was not able to make it work. I don't have an idea why the first solution for the f1, f2 and f3 keys works and hte solution for the combiantion keys does not work. I did notice the pomelos function triggers with the F3 function key instead of the F3+command.

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
LEGEND ,
Jan 09, 2022 Jan 09, 2022

Copy link to clipboard

Copied

Ah right, I missed out you wanted ctrlKey to be used together with F3. I corrected it.

 

I don't know if control, shift and alt works on macOs or you have to use something instead. See what held key message you get when using below code (with assigned F1), then being held what ever key (incl. command, option, control and shift):

refresh(), alert(ScriptUI.environment.keyboardState.keyName)

 

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 ,
Jan 10, 2022 Jan 10, 2022

Copy link to clipboard

Copied

LATEST

Thnak you, for the code. I will test it and let you I can make it work.

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