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

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

Community Beginner ,
Sep 04, 2023 Sep 04, 2023

Copy link to clipboard

Copied

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

 

TOPICS
Actions and scripting , macOS

Views

1.3K

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

Community Expert , Sep 08, 2023 Sep 08, 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

...

Votes

Translate

Translate
Community Expert , Sep 08, 2023 Sep 08, 2023

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

 

2023-09-09_10-36-28.png

Votes

Translate

Translate
Community Expert , Sep 09, 2023 Sep 09, 2023

Once the scripts are installed in the presets/scripts folder as previously linked to my blog post, you assign a custom keyboard shortcut to each script.

 

The script contains the conditional logic to match the document name to the appropriate action. This way you only need the same 7 shortcuts to automatically create 35 unique colours depending on which of the 5 templates are active.


I  personally like to understand the overall process first. Others may prefer to work through step by step.


Pleas

...

Votes

Translate

Translate
Community Expert , Sep 14, 2023 Sep 14, 2023
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:

 

...

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 04, 2023 Sep 04, 2023

Copy link to clipboard

Copied

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

Screenshot 2023-09-05 at 08.30.56.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
Community Beginner ,
Sep 05, 2023 Sep 05, 2023

Copy link to clipboard

Copied

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

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
Community Expert ,
Sep 05, 2023 Sep 05, 2023

Copy link to clipboard

Copied

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

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
Community Beginner ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

Thanks for the reply!

I'm not sure I understand your guidance. 

I've got a few different Photoshop templates. I'd like to have different actions for each template, but it seems as if the actions are set within Photoshop, and appear again in each new document. Unfortunately, if I'm only able to use the "F" keys (only 19 of them) there are not enough of them to cover all the different colors/actions I'm creating. So, I'd like to be able to create unique actions for each file/template. Is that possible?

thanks so much!

Roger

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
Community Expert ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

quote

Thanks for the reply!

I'm not sure I understand your guidance. 


By @Roger295904398732


My comments were general, you haven't provided any info to provide guidance. If you knew how to write such a script you wouldn't be asking if this was possible in the first place.

 

So, how is one template different to the others? 

Do they have different document names or different layer names? What is the unique identifier between the different templates?

 

How do you expect to automatically link different colours to different templates?

 

You know what is required, but how should Photoshop "know" this?


For example, if the template was named "cold" a script could automatically select an action named "blue" when a specific keyboard shortcut was pressed... But if the template was named "warm" then the same keyboard shortcut would select the action named "red".

 

If you have 5 defined colours, how many different templates do you have?

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
Community Beginner ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

Thanks for the reply. I greatly appreciate it!

 

Let me explain it this way...

 

1. I have five unique Photoshop files. They will be named differently. This is what I'm calling "templates."

2. For each of these templates, I will be simply drawing on them using the pen tool. 

3. Each template will have a pre-determined set of brush colors. Probably 6-8 colors each. 

4. What I am looking to do is create simple keyboard shortcuts/actions that will quickly switch between brush colors. 

5. I have already set up the first file/template. I have created the actions for seven colors, using the "F" keys (F1 thru F7). This works perfectly for this file. Exactly what I'm looking for. 

6. However, as I go to set up the second document, the actions for the first one show up. For lack of better terminology, it appears as if these actions reside within Photoshop, not an individual file. 

7. What I'm looking for, for example, is document/file/template #2 to use the same keyboard shortcuts, but for different brush colors. I say this because I may end up with 50+ unique colors, and I don't want to have to remember that many shortcuts. 

 

What I believe you're saying is that a script can be created to distinguish the file name, and from there change the action set based on that. So, if I open up file #1 and run the script, or perhaps it is set to run at startup (I'm not familiar with Apple Scripts), the script will determine what file I'm in and set the corresponding actions/brush colors. If I open up file #2, the same thing applies, and the scrip changes to the actions associate with that file. 

 

Am I understanding that correctly?

 

Sincerely grateful for the insight!

Roger

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
Community Expert ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

There are different ways to do this, but yes, the "condition" of a unique filename can be used to run a different action when the same keyboard shortcut is used to run an action.

 

what are the exact template names for 2 templates?

 

Can you post a screenshot of the action set and actions within the set?

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
Community Beginner ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

Two of the files are Chakra1 and Chakra2

 

ScreenShot.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
Community Beginner ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

The steps are exactly the same for each action. The only difference is the foreground color. 

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
Community Expert ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

Can you expand the three steps under the Root F1 action so that I can recreate the action for testing with the script that I'll write?

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
Community Beginner ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

ScreenshotREV.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
Community Expert ,
Sep 08, 2023 Sep 08, 2023

Copy link to clipboard

Copied

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

 

2023-09-09_10-20-37.png

 

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:

 

2023-09-09_10-27-49.png

 

Let me know if you need any help.

 

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
Community Expert ,
Sep 08, 2023 Sep 08, 2023

Copy link to clipboard

Copied

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

 

2023-09-09_10-36-28.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
Community Beginner ,
Sep 09, 2023 Sep 09, 2023

Copy link to clipboard

Copied

@Stephen_A_Marsh 

 

Thank you so much for this! This is so above and beyond!

 

I think I understand this. I'm going to have to spend a day or two absorbing it and seeing if I can get it to work. I'm not sure yet where I create the scripts, but I think I can figure that out. 

 

Thanks again for the time and effort on this! I'm very grateful!

 

Roger

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
Community Expert ,
Sep 09, 2023 Sep 09, 2023

Copy link to clipboard

Copied

quoteI'm not sure yet where I create the scripts, but I think I can figure that out. 


You're welcome!

 

The starter script code can be copied and pasted into any plain text editor, more here:

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html


Do post back if you get stuck or need any clarification.

 

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
Community Beginner ,
Sep 09, 2023 Sep 09, 2023

Copy link to clipboard

Copied

@Stephen_A_Marsh 

 

Quick question...what activates each action within the action set, if it is not the "F" keys? 

 

If the script has identified "Chakra1" as the file, and associates that with an action set, what allows me to move through the seven colors within that action? How do I get from Chakra1_Root to Chakra1_Sacral to...Chakra1_Solar to Chakra1_Heart...? It seems like without some keystroke it will not move from one to the next. 

 

I hope I'm asking that correctly.

 

Thanks,

Roger

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
Community Expert ,
Sep 09, 2023 Sep 09, 2023

Copy link to clipboard

Copied

Once the scripts are installed in the presets/scripts folder as previously linked to my blog post, you assign a custom keyboard shortcut to each script.

 

The script contains the conditional logic to match the document name to the appropriate action. This way you only need the same 7 shortcuts to automatically create 35 unique colours depending on which of the 5 templates are active.


I  personally like to understand the overall process first. Others may prefer to work through step by step.


Please review my previous 2 posts where the entire process was detailed. It may take more than one read for the concept to become clear.

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
Community Beginner ,
Sep 10, 2023 Sep 10, 2023

Copy link to clipboard

Copied

Thanks again! I'm working through it!

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
Community Expert ,
Sep 10, 2023 Sep 10, 2023

Copy link to clipboard

Copied

Just let me know if you get stuck. Although I believe that I have detailed the process in a logical and concise fashion, I may not have!

 

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
Community Beginner ,
Sep 11, 2023 Sep 11, 2023

Copy link to clipboard

Copied

Thanks!

 

I've simplified this on my end. I now have three templates (instead of 5) and 8 actions for each. So, I have 24 total actions. 

 

Therefore, if I'm understanding it all correctly, I'll have 8 scripts/shortcuts that will set the correct color based on which template I'm in. So, like before, if I use "F1" as a shortcut for "Root," the script will determine which file I'm in and select the appropriate action/color. That's exactly what I'm hoping for. 

 

I've modified the script steps to match my new files/actions. I have them into Script Editor. I'm getting some kind of syntax error, but I think I'm close...

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
Community Beginner ,
Sep 11, 2023 Sep 11, 2023

Copy link to clipboard

Copied

AppleScript.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
Community Expert ,
Sep 11, 2023 Sep 11, 2023

Copy link to clipboard

Copied

I wrote in my previously linked blogpost:

 

"To avoid unexpected issues, only use Apple Script Editor for AppleScript code, not JavaScript 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
Community Expert ,
Sep 11, 2023 Sep 11, 2023

Copy link to clipboard

Copied

No, ScriptEditor isn't for Adobe ExtendScript, stay away from that!

 

This code is ExtendScript/JavaScript.

 

Look for "Text Editor Applications" listed in my blogpost for appropriate plain text editors.

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
Community Beginner ,
Sep 11, 2023 Sep 11, 2023

Copy link to clipboard

Copied

Thanks again for all the help! I'm beyond grateful!

Roger

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