Copy link to clipboard
Copied
I'm wondering if it's possible to make the program press a specific key (in my case - the escape key which has the key code 27 afaik)?
I'm not going to use this to enter text into a field - but only to trigger the reset of a tool (rotate tool). As far as I know, resetting the rotate tool does not produce a result in the script listener nor does it produce a result when recording an action, which is why I'm looking into doing this with a script instead (by switching to the rotate tool and hitting Esc).
Javascript is the prefered language here as I know it the best, but VBscript will be fine as well.
Copy link to clipboard
Copied
I don't think JS will let you do that - mainly for security reasons. They want actual keyboad input. However, you can record resetting the rotate tool with this code:
var idslct = charIDToTypeID( "slct" );
var desc4 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref3 = new ActionReference();
var idrotateTool = stringIDToTypeID( "rotateTool" );
ref3.putClass( idrotateTool );
desc4.putReference( idnull, ref3 );
var iddontRecord = stringIDToTypeID( "dontRecord" );
desc4.putBoolean( iddontRecord, true );
var idforceNotify = stringIDToTypeID( "forceNotify" );
desc4.putBoolean( idforceNotify, true );
executeAction( idslct, desc4, DialogModes.NO );
Copy link to clipboard
Copied
Thanks, but that script doesn't seem to do anything for me.
I created a new document, selected the rotate tool, rotated a bit and then ran the script and nothing happend.
Copy link to clipboard
Copied
Yea, looking at the code, it is just for selection the rotation tool. The scriptlistener doesn't seem to record the actual reset.
Copy link to clipboard
Copied
And strangely one can access an angle-feature via the currentToolOptions but it seems to be 0 no matter what.
#target "photoshop-70.032"
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var docDesc = executeActionGet(ref);
var cTO = docDesc.getObjectValue(stringIDToTypeID("currentToolOptions"));
var theAngle = cTO.getUnitDoubleValue(stringIDToTypeID("angle"));
alert (theAngle);
Check out
Copy link to clipboard
Copied
Thanks.
So basicly the answer is: No, this is entirely impossible because the rotate tool was coded in a stupid way.
Copy link to clipboard
Copied
While it may have been implemented in a thrifty manner this does not quite justify the term you used in my opinion.
You have to consider that the people who »really« take advantage of Photoshop Scripting are probably only a very small part of Photoshop users overall.
But feel free to post a Feature Request over at
http://feedback.photoshop.com/photoshop_family/
and let us know the link so we may add support to a request for improved Scripting capabilities for the Tool.
Copy link to clipboard
Copied
Maybe that word is a bit over the line but you have to agree that there is something funky going on with that tool.
For example: I now discovered that resetting that tool actually does nothing to the tool (ie: it's by definition a bug). Try it yourself, rotate the workfile a bit, then click the tool icon in the upper left corner > gear icon > reset tool.
Now, this action is actually scripted - and this is the output I got from the script listener:
var idRset = charIDToTypeID( "Rset" );
var desc12 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref10 = new ActionReference();
var idPrpr = charIDToTypeID( "Prpr" );
var idCrnT = charIDToTypeID( "CrnT" );
ref10.putProperty( idPrpr, idCrnT );
var idcapp = charIDToTypeID( "capp" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref10.putEnumerated( idcapp, idOrdn, idTrgt );
desc12.putReference( idnull, ref10 );
executeAction( idRset, desc12, DialogModes.NO );
...but like I said, the rotate tool is not really affected by this functionality.
Copy link to clipboard
Copied
I think the Tool Reset is only intended to affect »Rotate All Windows«.
Copy link to clipboard
Copied
Yea it does - but you can't claim it's intentional.
Either way, I guess this is simply impossible like I stated earlier. Javascript is too high-level to allow a simulated key press (Esc in this case), and the functionality of the rotate tool is either bugged and/or too deep into the API to be scripted. What a shame...
Copy link to clipboard
Copied
I think another issue with this is that this type of function normally just isn't really implemented well in script. Most script are meant to run a full series of commands with little to no user interface. something like resetting the rotation means that there was or is user interaction in using the image rotated. So just being able to hit the esc key, in most cases would be just as easy, if not easier that running a script to do so.
Copy link to clipboard
Copied
Most script are meant to run a full series of commands with little to no user interface.
I think the observation is accurate: image manipulation is largely Scriptable, interface not so much.
For example I suppose over the years a couple of people may have had the idea to try and store the window positions and positions and zoom factors of the images in the windows to be able to recreate a »session« – but that involves parameters that are just not Scriptable so far (and may never be).
Copy link to clipboard
Copied
Yea it does - but you can't claim it's intentional.
I’m not trying to be antagonistic on this, but I disagree.
I think the Angle is intended to be a document specific setting, not a Tool setting.
Kind of like if you reset a Selection Tool you would not want that to affect an active Selection.
As for the key-hits: On Mac one can use AppleScript in JavaScript but as far as I can tell only the tab-key actually works in an example I found.
Copy link to clipboard
Copied
This is a functiom which triggers right arrow key on OSX. Im still looking for a Windows equivalent to trigger arrow key from system. If any one knows one, ill be very happy
// Execute keypress OS
// https://www.ps-scripts.com/viewtopic.php?f=66&t=7614&p=37657&hilit=key+press#p37657
// keycodes OSX > https://eastmanreference.com/complete-list-of-applescript-key-codes#:~:text=The%20enter%20key%20on%20most,accomplished%20by%20hitting%20fn%20%2B%20enter.
function keyPress(os){
// #target photoshop
// app.bringToFront();
// 123 left
// 124 right
// 126 up
// 125 down
// 116 PgUp
// 121 PgDn
// 115 Home
// 119 End
// alert(os)
// $.sleep (100);
// Check OS
if (os == "Windows") {
// WIP get windows equilant code
} else if (os == "Mac") {
// alert(os)
app.system( 'osascript -e \'tell application "System Events" to key code "124"\'' );
// app.system( 'osascript -e \'tell application "System Events" to key code "123" using command down\'' );
}
}
Copy link to clipboard
Copied
I found something which sort of works, it will show a the cscript window for a millisecond but it does run the vbs file. The only thing i dont understand is why the vbs file wont run from inside roaming folder or photoshop folder. I only get it to work running from desktop or documents folder. Probably some admin issue i guess.
// alert(File("C:/Program Files/Common Files/Adobe/CEP/extensions/com.sbaril.animdessin2/jsx/arrowright.vbs").exists)
var path = 'cscript //nologo C:/Users/romboutversluijs/documents/Adobe/CEP/AnimDessin2/arrowright.vbs'; // ROmaing folder
try{
app.system(path);
} catch(e){
alert(e)
}
Copy link to clipboard
Copied
I found a better method, this one wont show a flashing command window. First i didnt got it working so i thought something was wrong. Tried it a couple times more and works like a champ, no flashing command window 🙂
source from this thread post
try{
var mb_keystrF = new File(File(getPrefFolder()+'/amd2-shortcut.vbs'));
var str = 'Set WshShell = WScript.CreateObject("WScript.Shell")\
WshShell.SendKeys "{RIGHT}"';
mb_keystrF.open('w');
mb_keystrF.write(str);
mb_keystrF.close();
mb_keystrF.execute();
} catch(e){
alert(e)
}
Copy link to clipboard
Copied
There are people who know more about the action manager, who might know if this is possible. However, there are a lot of things in PS that just can't be scripted. This might be one of them. You might want to try posting your question on ps-scripts.com also.
Copy link to clipboard
Copied
There are people who know more about the action manager, who might know if this is possible.
True that.
I certainly can’t rule it out.
You might want to try posting your question on ps-scripts.com also.
Also a valid recommendation.
But that Forum seems to be fairly slow lately, what with Paul and xbytor having »turned their backs« on the matter …
Copy link to clipboard
Copied
I did post this question on ps-scripts.com as well.
But like you I get the impression that the forum is "slow". Actually it's borderline deserted considering how few replies threads get there - often not getting any replies at all even to simple questions.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now