Get selected workspace in Photoshop

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: xbytor, DavideBarranca, Paul MR

nfrasser
Posts: 2
Joined: Fri Jan 20, 2017 5:13 pm

Get selected workspace in Photoshop

Postby nfrasser » Mon Jan 23, 2017 4:19 pm

I'm looking for a script to get the currently-selected workspace from Photoshop. If possible, I'd also like to get a list of available workspaces. This is for a plugin I'm building that can cycle through workspaces based on user input.

I already have the script to select a specific workspace by name, which I got from the ScriptListener plugin:

Code: Select all

var idslct = charIDToTypeID( "slct" );
var desc5 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idworkspace = stringIDToTypeID( "workspace" );
ref1.putName( idworkspace, "Photography" ); // substitute "Photography" with any workspace name
desc5.putReference( idnull, ref1 );
executeAction( idslct, desc5, DialogModes.NO );

JavierAroche
Posts: 29
Joined: Sat Jul 30, 2016 3:52 am

Re: Get selected workspace in Photoshop

Postby JavierAroche » Tue Jan 24, 2017 7:41 pm

If you use my descriptor-info module, you can use the example JSX under the "example" folder, and replace the code in that JSX with this:

Code: Select all

// Include the JSON helper
#include "./helpers/JSON.jsx"
// Include the descriptor-info module
#include "../jsx/descriptor-info.jsx"

// ActionDescriptor example
var ref = new ActionReference();
ref.putProperty( stringIDToTypeID("property"), stringIDToTypeID("workspaceList") );
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);

var descObject = descriptorInfo.getProperties( desc );

// Running in ExtendScript
$.writeln(JSON.stringify(descObject, null, 4));
This will get you the workspace list as an object. Unfortunately, it doesn't specify which one is selected, and I can't find that property.

This is the result object you would get:

Code: Select all

{
"workspaceList": [
{
"workspace": {
"displayName": "hello",
"name": "hello",
"user": true
}
},
{
"workspace": {
"displayName": "Essentials",
"name": "Essentials",
"user": false
}
},
{
"workspace": {
"displayName": "3D",
"name": "3D",
"user": false
}
},
{
"workspace": {
"displayName": "Motion",
"name": "Motion",
"user": false
}
},
{
"workspace": {
"displayName": "Painting",
"name": "Painting",
"user": false
}
},
{
"workspace": {
"displayName": "Photography",
"name": "Photography",
"user": false
}
},
{
"workspace": {
"displayName": "Typography",
"name": "Typography",
"user": false
}
}
]
}
You can achieve this without using the descriptor-info module, but you will need to manually loop through the descriptors in the list (contained in "desc" variable), to get each workspace properties.

pixxxelschubser
Posts: 26
Joined: Mon Aug 01, 2016 8:59 pm

Re: Get selected workspace in Photoshop

Postby pixxxelschubser » Tue Jan 24, 2017 8:41 pm

Same procedure, without json

Code: Select all

alert(listAllWorkspaces().join("\n"));
function listAllWorkspaces () {
var ref = new ActionReference();
Info = new Array();
ref.putProperty( charIDToTypeID("Prpr"), stringIDToTypeID("workspaceList") );
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref).getList( stringIDToTypeID("workspaceList") );
for(var i = 0; i<desc.count; i++) {
var Nme = desc.getObjectValue(i).getString( stringIDToTypeID("name") );
Info.push(Nme);
}
return Info;
};
Will gives you the names of your workspaces, but not the active workspace.

JavierAroche
Posts: 29
Joined: Sat Jul 30, 2016 3:52 am

Re: Get selected workspace in Photoshop

Postby JavierAroche » Wed Jan 25, 2017 4:36 am

Yep that's what I meant when I said you'd have to manually loop through the descriptors in the list :D


Return to “Help Me”

Who is online

Users browsing this forum: No registered users and 4 guests