Skip to main content
Participant
April 16, 2015
Question

How can I extract cursor coordinate in Adobe Photoshop for use in Action script?

  • April 16, 2015
  • 2 replies
  • 4215 views

What I want to do in Photoshop (version CC, but I think this applies to any version) is label a point using count tool under my mouse's current position, and label it multiple times (for different labels). I have an action that essentially does this:

(1) Add to count (under one label) (2) Switch to second label (3) Add to count (under second label) (4) Switch to third label (5) Add to count (under third label)

And the problem is that I need to be able to have a variable in the action script that uses the cursor's current position (X and Y numbers) on the canvas to set these three points when the macro is activated. Currently I am only able to record the script using constant X, Y values (the same point is labeled over and over when I play the recorded action). I am able to extract the code for the action for editing (via xbytor2's suggestion in this forum:https://forums.adobe.com/thread/696989) and I see where the variable can go, I just don't know what exactly to put in place of the constant X, Y values that will let Photoshop input the mouse's current coordinates...

Any ideas? Much appreciated!!

This topic has been closed for replies.

2 replies

DBarranca
Legend
April 16, 2015

Hi,

I'm afraid it's not completely clear to me what you're after, yet if I understand you're asking whether it is possible to retrieve via scripting the live X/Y coordinates of the mouse pointer (as the Info palette shows when you move it) - am I right?

To the best of my knowledge, the answer is no - I requested this feature a while ago, but it's never been implemented. I'd be glad to be proved wrong!

Hope this helps,

Davide Barranca

---

www.davidebarranca.com

www.cs-extensions.com

jsmart17Author
Participant
April 17, 2015

Yes, the info palette X/Y values are what I am after. The program already seems to be storing that information somewhere (in a variable?) in order to display it, and so ideally, and most simply, I can just input those X/Y variable names into my action script to mark live points...

Do you know if there is a way to view the coding for the info palette? I'm not sure if that's allowed...

DBarranca
Legend
April 17, 2015

Your point is exactly the same I made - the info is available live to PS, yet it's not exposed via the DOM (nor via ActionManager).

Davide

Inspiring
April 16, 2015

You could use the pen tool set to path and create a single dot, then run the script to get the cursor positions and use that in your script.

var strtRulerUnits = app.preferences.rulerUnits;

var strtTypeUnits = app.preferences.typeUnits;

app.preferences.rulerUnits = Units.PIXELS;

app.preferences.typeUnits = TypeUnits.PIXELS;

var doc = activeDocument;

var workPath = doc.pathItems.getByName("Work Path");

var pos = workPath.subPathItems[0].pathPoints[0].leftDirection;

$.writeln("x = " + pos[0] + " y = " + pos[1]);

doc.pathItems.getByName("Work Path").remove();

app.preferences.rulerUnits = strtRulerUnits;

app.preferences.typeUnits = strtTypeUnits;

jsmart17Author
Participant
April 17, 2015

Thank you for this neat suggestion, I will try it soon and get back to you.