Skip to main content
Stephen Marsh
Community Expert
Community Expert
January 7, 2025
Answered

Script to Get the Active Workspace Name

  • January 7, 2025
  • 1 reply
  • 599 views

I found the following topic and code, where the active workspace can be loaded by name:

 

function sTT(v) {
    return stringIDToTypeID(v)
} 
(ref = new ActionReference()).putName (sTT('workspace'), 'Essentials'); 
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref);
executeAction(sTT('select'), dsc);
executeAction(sTT('reset'), dsc);

 

Is there a way to script the retrieval of the current workspace?

 

My final goal is to write the workspace's name to a text log file (among other things) and then load the named workspace at a later time. 

Correct answer c.pfaffenbichler
// determine active workspace;
// 2025, use it at your own risk;
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("menuBarInfo"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var xxx = executeActionGet(r).getObjectValue(stringIDToTypeID("menuBarInfo")).getList(stringIDToTypeID("submenu"));
for (var m = 0; m < xxx.count; m++) {
var thisOne = xxx.getObjectValue(m);
// get window menu;
if (thisOne.getString(stringIDToTypeID("title")) == "Window") {
var view_submenus = executeActionGet(r).getObjectValue(stringIDToTypeID("menuBarInfo")).getList(stringIDToTypeID("submenu")).getObjectValue(m).getList(stringIDToTypeID("submenu"));
}
};
// get workspace menu;
for (var m = 0; m < view_submenus.count; m++) {
var thisOne = view_submenus.getObjectValue(m);
if (thisOne.getString(stringIDToTypeID("title")) == "Workspace") {
var thisSubMenu = thisOne.getList(stringIDToTypeID("submenu"));
for (var n = 0; n < thisSubMenu.count; n++) {
    var checked = thisSubMenu.getObjectValue(n).getBoolean(stringIDToTypeID("checked"));
    if (checked == true) {
        alert (thisSubMenu.getObjectValue(n).getString(stringIDToTypeID("title")))
    }
};
}
};

1 reply

Legend
January 9, 2025

Tried it, but target ordinal's workspace name could not be taken directly. Maybe I'm doing it wrong.

 

Technically, the current workspace can be obtained by getting application.menuBarInfo, and then referring to the name of the menu in Window > Workspace that has the checked value true.

 

That means in the ActionDescriptor.

Stephen Marsh
Community Expert
Community Expert
January 9, 2025

@sttk3 – thank you for the reply, my AM knowledge is next to zero, this topic isn't critical to me, just something that would be "nice to do".

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
January 9, 2025
// determine active workspace;
// 2025, use it at your own risk;
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("menuBarInfo"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var xxx = executeActionGet(r).getObjectValue(stringIDToTypeID("menuBarInfo")).getList(stringIDToTypeID("submenu"));
for (var m = 0; m < xxx.count; m++) {
var thisOne = xxx.getObjectValue(m);
// get window menu;
if (thisOne.getString(stringIDToTypeID("title")) == "Window") {
var view_submenus = executeActionGet(r).getObjectValue(stringIDToTypeID("menuBarInfo")).getList(stringIDToTypeID("submenu")).getObjectValue(m).getList(stringIDToTypeID("submenu"));
}
};
// get workspace menu;
for (var m = 0; m < view_submenus.count; m++) {
var thisOne = view_submenus.getObjectValue(m);
if (thisOne.getString(stringIDToTypeID("title")) == "Workspace") {
var thisSubMenu = thisOne.getList(stringIDToTypeID("submenu"));
for (var n = 0; n < thisSubMenu.count; n++) {
    var checked = thisSubMenu.getObjectValue(n).getBoolean(stringIDToTypeID("checked"));
    if (checked == true) {
        alert (thisSubMenu.getObjectValue(n).getString(stringIDToTypeID("title")))
    }
};
}
};