Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Cycling flow and opacity in Photoshop


  • Please log in to reply
2 replies to this topic
tenderchkn
  • New members
  • 2 posts
  • Last active: Sep 30 2015 06:33 AM
  • Joined: 28 Sep 2015

I want to create a script that can cycle brush opacity and flow settings in Photoshop. I know that I can easily bind a specific hotkey to a specfic opacity/flow percentage, but that requires one hotkey per setting. I want to be able to bind just two keys, such that one increases the current value and the other decreases the current value.

 

In order to do that, the script would need to read the current setting, and then send a variable keystroke to apply the new setting.

 

I'm not experienced in scripting, and would like some help to get started in the right direction. What is the best way to have AHK read and store the current setting? I am fine with it assuming a certain setting when it starts (i.e. 100% or 1%), and have it cycle up or down from there. Will it be easiest to have a loop that stores a counter value that gets +1 or -1 each time the loop executes?



tenderchkn
  • New members
  • 2 posts
  • Last active: Sep 30 2015 06:33 AM
  • Joined: 28 Sep 2015

Did some more research and this is what I came up with. It can probably be better and more optimized, so please let me know if there are any obvious things that can be improved.

 

Array := ["01", "02", "04", "07", "10", "15", "20", "30", "40", "50", "75", "100"]      
OpacityCount := Array.MaxIndex()
FlowCount := 1
return


F12::
FlowCount ++
Send {Shift Down}
Send,    %    Array[FlowCount]
Send {Shift Up}
if (FlowCount > Array.MaxIndex())
    FlowCount := Array.MaxIndex()
return

+F12::
OpacityCount ++
Send,    %    Array[OpacityCount]
if (OpacityCount > Array.MaxIndex())
    OpacityCount := Array.MaxIndex()
return

F11::
FlowCount --
Send {Shift Down}
Send,    %    Array[FlowCount]
Send {Shift Up}
if (FlowCount < 1)
    FlowCount := 1
return

+F11::
OpacityCount --
Send,    %    Array[OpacityCount]
if (OpacityCount < 1)
    OpacityCount := 1
return



scriptor
  • Members
  • 668 posts
  • Last active: Feb 15 2016 01:02 AM
  • Joined: 20 Jun 2013

I put together a script which is a total mess and a hack job, but for what it's worth it works on my end, although it's flakey and I think it's susceptible to errors and bugs simply because of the way Photoshop is so sensitive in its interface. But you could always examine the code and improve on it. Before running it:

 

-make sure your options bar is visible, docked and not floating. If it's floating (ie. if it's not attached just below the top menu bar) then it messes with the ahk_class and it changes from 'ahk_class Photoshop' to 'ahk_class OWL.ControlBarContainer'. If you must have the options bar floating and you like to move it around the screen, then change the class name in the script wherever it appears. But I think it's safest to keep it docked and use the script as is.

 

-pressing 1 will decrease the brush opacity, and pressing 2 will increase it. Don't press 1 or 2 too fast in succession, wait a few milliseconds before pressing a second, third, fourth time etc. If it's pressed too quickly I'm not sure what happens but I think it might bug out- it can be fixed but this is just a start. But of greater interest is that if I simply hold down 1 or 2, then the opacity continues to increase or decrease until I let go of 1 or 2. For some reason pressing it repeatedly too fast seems to not work as well, but holding it down works fine. Try both.

 

-close all other scripts that are running so you have a clean access to hotkeys keys 1 and 2. Or, just change the hotkeys to whatever you want

 

I wrote in a clause that if the opacity exceeds 100%, it will avoid the error pop up message the Photoshop throws, and keep the opacity at 100%. Same goes for 0%. I was going to add in a tooltip to display the current opacity, (which is pretty easy actually) but I can add that in later after being sure this actually works for you.

 

And last, if you get problems, try re-enabling both 'sleep, 250' lines to see if it helps - it works on my sytsem without it but I've been working with Photoshop long enough to know that what works today might not work tomorrow when automating it with AHK. Here it is (again it ain't pretty but she works):

1::
winactivate, ahk_class Photoshop
Controlgettext, ValueB, Edit2, ahk_class Photoshop
String := ValueB
StringTrimRight, OutputVarB, String, 1
Value2B := OutputVarB

Adjustment02 := Value2B-10
ControlSetText, Edit2, %Adjustment02%, ahk_class Photoshop
 
;sleep, 250 

Controlgettext, Adjustment04, Edit2, ahk_class Photoshop
If Adjustment04 <= 0
{
ControlSetText, Edit2, 1`%, ahk_class Photoshop 
sendinput, {enter} 
SoundPlay, %A_WinDir%\Media\ding.wav
winactivate, ahk_class Photoshop
}
else
{
ControlClick, Edit2, ahk_class Photoshop
sendinput {right 4}
sendinput, {lshift down}{sc006}{lshift up}  
sendinput {enter}
SoundPlay, %A_WinDir%\Media\ding.wav
winactivate, ahk_class Photoshop
return
}
return


2::
winactivate, ahk_class Photoshop
Controlgettext, ValueA, Edit2, ahk_class Photoshop
String := ValueA
StringTrimRight, OutputVarA, String, 1
Value2A := OutputVarA

Adjustment01 := Value2A+10
ControlSetText, Edit2, %Adjustment01%, ahk_class Photoshop

;sleep, 250

Controlgettext, Adjustment03, Edit2, ahk_class Photoshop
If Adjustment03 > 100
{
ControlSetText, Edit2, 100`%, ahk_class Photoshop 
sendinput {enter}
SoundPlay, %A_WinDir%\Media\ding.wav
winactivate, ahk_class Photoshop
}
else
{
ControlClick, Edit2, ahk_class Photoshop
sendinput {right 4}
sendinput, {lshift down}{sc006}{lshift up}  
sendinput {enter}
SoundPlay, %A_WinDir%\Media\ding.wav
winactivate, ahk_class Photoshop
return
}
return