Skip to main content
Participating Frequently
September 4, 2023
Answered

Photoshop keyboard shortcut (Action or script) for changing brush colors

  • September 4, 2023
  • 3 replies
  • 2313 views

Hello,

 

I am trying to set up some automation for changing brush colors in Photoshop. 

 

Let's say that I have five defined colors that I want to use while drawing. Rather than go through the standard steps to change the color, I'd like to assign each color to a keyboard shortcut. Then, when I press the key the color changes automatically. I'm assuming this would require some action or script, but this is beyond my knowledge.

 

Can someone point me in the right direction?

 

Thanks!

Roger

 

This topic has been closed for replies.
Correct answer Stephen Marsh

Thank you.

 

Here is what I've done. I actually have a significant amount of scripting experience (using FilemakerPro), and I know that even the tiniest of mistakes in punctuation, logic, etc., can make the script useless. I just don't have that knowledge with this language. It's possible that I've executed one of the tiny mistakes, or more likely I'm way off target...


quote

Thank you.

 

Here is what I've done. I actually have a significant amount of scripting experience (using FilemakerPro), and I know that even the tiniest of mistakes in punctuation, logic, etc., can make the script useless. I just don't have that knowledge with this language. It's possible that I've executed one of the tiny mistakes, or more likely I'm way off target...


By @Roger295904398732

 

Yes, simple mistakes, easily fixed!

 

You need to "close off" all of the conditionals with a final:

 

} else {}

 

Compare your edits to my original code. Or change the last "else if" to an "else":

 

https://www.w3schools.com/js/js_if_else.asp

 

The greyed-out file has an extra period/dot AFTER .jsx.

 

3 replies

c.pfaffenbichler
Community Expert
Community Expert
September 10, 2023

If @Stephen Marsh ’s post/s solved the issue please remember to mark the correct answer as such. 

Stephen Marsh
Community Expert
Community Expert
September 9, 2023

@Roger295904398732 

 

I have created a proof of concept action and script that works as expected.

 

Here is my action, similar to yours, however:

 

1) You can record creating a new layer with the ALT/OPT key depressed to create the layer via a dialog which allows you to create and name in a single step

 

2) I have removed the F key shortcuts from the action, as they are assigned to the script, not the action.

 

3) Also note that the action name includes the template name, this way the script can match up the correct action to the correct template.

 

 

There are 5 templates and 7 colours, so you will need to create 35 actions in the set.

 

Here is the proof of concept code for Root:

 

// CONDITION 1
if (app.activeDocument.name.indexOf('Chakra1') != -1) {
    app.doAction('Chakra1 - Root', 'Chakras');

// CONDITION 2
} else if (app.activeDocument.name.indexOf('Chakra2') != -1) {
    app.doAction('Chakra2 - Root', 'Chakras');

} else {}

 

Here is the proof of concept code for Sacral:

 

// CONDITION 1
if (app.activeDocument.name.indexOf('Chakra1') != -1) {
    app.doAction('Chakra1 - Sacral', 'Chakras');

// CONDITION 2
} else if (app.activeDocument.name.indexOf('Chakra2') != -1) {
    app.doAction('Chakra2 - Sacral', 'Chakras');

} else {}

 

In each case, I have only created 2 of the 7 conditions. All you need to do is dupe condition 2 and change it for each of the other 5 conditions, changing the active document name from 'Chakra2' to 'Chakra3' etc. and the corresponding action name Chakra2 to Chakra3 etc. You will also need to change Sacral to Heart etc. where needed.

 

The 5 .jsx scripts (one for each template) need to be installed in the application folder's presets/scripts folder.

 

The script is triggered by the F keys, just like your actions were, using custom keyboard shortcuts for application menus, file > scripts:

 

 

Let me know if you need any help.

 

Stephen Marsh
Community Expert
Community Expert
September 9, 2023

Here is a visual of how the script code and action work together:

 

Participating Frequently
September 15, 2023
quote

IT WORKED!!!!!


By @Roger295904398732

 

Fantastic! So, where do you now stand?


I feel much better about it now. I did realize that it wasn't working earlier, for one, because I had actually changed the name of the actions, and didn't change it in the script! Rookie mistake! But now that this first one is working, I know I'll be able to go through and set up all the other colors/scripts without any problem. 

 

Thanks again for all the help! It was above and beyond. I'm very grateful!

 

Thanks!

Roger

c.pfaffenbichler
Community Expert
Community Expert
September 5, 2023

Record setting the forground color in a new Action and assign a shortcut to the Action. 

Create actions in Adobe PhotoshopAdobehttps://helpx.adobe.com › using › creating-actions

Participating Frequently
September 5, 2023

This is excellent! So easy! Thank you so much!

 

Let me ask another question, if I may. Is it possible to assign these actions to a specific PSD file, rather than overall "Photoshop" actions that are the same for all files? I'd like to have, for example, 7 colors/actions for one particular template, but a different set of colors/actions for another template. 

 

Is this possible? 

Thanks again!

Roger

Stephen Marsh
Community Expert
Community Expert
September 5, 2023

@Roger295904398732 

 

A script can check the active document name or layer name and conditionally run a different action set/action for a different foreground colour. Or the script could just change the foreground colour without needing to reference an action.