Get Currently Selected / Highlghted Text

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

robustrory
Posts: 3
Joined: Mon Jan 14, 2019 3:49 am

Get Currently Selected / Highlghted Text

Post by robustrory »

Hey there, I've been wandering around the barren land of documentation for a while now, thought I'd try my hand at asking for help.

I'm trying to get the selected / highlighted text when using the text tool.
I've stumbled across / figured out a lot of the other aspects i need, but I haven't yet figured out how to get the actual selection start and end (text range).
Using the Action Manager / Description world I can iterate over the textStyleRanges, but I don't know how to tell which one is currently highlighted.. I see the 'from' and 'to' of each range, but that's it.

Image
robustrory
Posts: 3
Joined: Mon Jan 14, 2019 3:49 am

Re: Get Currently Selected / Highlghted Text

Post by robustrory »

From the lack of responses and also through my own investigation, I'm thinking this is not possible.
Using the script listener, I see that the changes to the TextItem's From and To properties are passed raw values, not fetched by using an ActionDescriptor:

var idFrom = charIDToTypeID( "From" );
desc169.putInteger( idFrom, 28 );
var idT = charIDToTypeID( "T " );
desc169.putInteger( idT, 40 );

I'd expect the 28 and 40 above to be retrieved in some way if this was possible. 28 and 40 represent the beginning and end of a text range. Essentially, the highlighted section in the screenshot to my last post.

Unless someone knows some way to do it and is willing to speak up, I figured I would leave another post to help anyone reach my conclusion a couple days sooner.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Get Currently Selected / Highlghted Text

Post by Kukurykus »

That's not possible as highlighted text make Photoshop waits to commit 'changes' even if you only highlighted text, but didn't start to edit it. Only way to do what you want is to involve external application wrote by for ex. autohotky.com if you are on Windows, are you?
robustrory
Posts: 3
Joined: Mon Jan 14, 2019 3:49 am

Re: Get Currently Selected / Highlghted Text

Post by robustrory »

Hey Kukurykus , thanks for the response. I am on windows.
i noticed there was the "commit" phase for text changes, as well.

When you say:
Only way to do what you want is to involve external application
is this a standard practice for plugin authors?
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Get Currently Selected / Highlghted Text

Post by Kukurykus »

No, it's not, and it would work for Windows only if you used AHK I mentioned in previous post.