Skip to main content
danielw42205661
Known Participant
February 15, 2023
Answered

Script to cycle between 2 user workspaces

  • February 15, 2023
  • 2 replies
  • 983 views

Hoping this is a simple thing to do and if someone would be kind enough to provide some script code for it.

 

I have 2 user workspaces called Dan1 and Dan2. Instead of manually changing the workspace every time I want to use the other one i'd like to assign a shortcut to the script that cycles between the two. Many thanks.

This topic has been closed for replies.
Correct answer m1b

Here's a little script to do this. There are two limitations:

1. As far as I can tell, we can't tell which workspace is active, so I just have to start at the beginning. This means the first time you run the script in each session you may have to toggle twice to get the workspace you want. 

2. Can you add a keyboard shortcut to a script? You may need a third party app to help? Sorry I'm not sure about that.

- Mark

/**
 * Toggle between workspaces.
 * @7111211 m1b
 * @version 2023-02-15
 * @discussion https://community.adobe.com/t5/indesign-discussions/script-to-cycle-between-2-user-workspaces/m-p/13580436
 */

// Put your workspace names here:
var workspaceNames = ['Dan1', 'Dan2'],

    key = 'workspaceForDan',
    currentValue = app.extractLabel(key),
    index = indexOf(currentValue, workspaceNames),
    newIndex = index == -1 ? 0 : (index + 1) % workspaceNames.length,
    newValue = workspaceNames[newIndex];

app.insertLabel(key, newValue);
app.applyWorkspace(newValue);

function indexOf(obj, arr) {
    for (var i = 0; i < arr.length; i++) if (arr[i] === obj) return i;
    return -1;
};

 

2 replies

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
February 15, 2023

Here's a little script to do this. There are two limitations:

1. As far as I can tell, we can't tell which workspace is active, so I just have to start at the beginning. This means the first time you run the script in each session you may have to toggle twice to get the workspace you want. 

2. Can you add a keyboard shortcut to a script? You may need a third party app to help? Sorry I'm not sure about that.

- Mark

/**
 * Toggle between workspaces.
 * @7111211 m1b
 * @version 2023-02-15
 * @discussion https://community.adobe.com/t5/indesign-discussions/script-to-cycle-between-2-user-workspaces/m-p/13580436
 */

// Put your workspace names here:
var workspaceNames = ['Dan1', 'Dan2'],

    key = 'workspaceForDan',
    currentValue = app.extractLabel(key),
    index = indexOf(currentValue, workspaceNames),
    newIndex = index == -1 ? 0 : (index + 1) % workspaceNames.length,
    newValue = workspaceNames[newIndex];

app.insertLabel(key, newValue);
app.applyWorkspace(newValue);

function indexOf(obj, arr) {
    for (var i = 0; i < arr.length; i++) if (arr[i] === obj) return i;
    return -1;
};

 

danielw42205661
Known Participant
February 15, 2023

Thanks so much @m1b 

 

Just tested it and it works great. Yep you can assign shortcuts to scripts within indesign.

m1b
Community Expert
Community Expert
February 15, 2023

Nice!

m1b
Community Expert
Community Expert
February 15, 2023

Hi @danielw42205661, you might not need a script. Try using Edit > Keyboard Shortcuts... and choose the Window Menu.

- Mark

danielw42205661
Known Participant
February 15, 2023

Thanks. I know about that, but I would then need 2 shortcuts (1 for each workspace) instead of 1 that cycles between the 2. Which isn't really what I want.