A couple changes:
*improved the dialog for selection
*@ngan added code to close all open windows before loading the new ones
-- Load Workspace
-- from a list of all saved workspaces
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application id "DNtp"
try
set theWorkspaces to workspaces
set mychoice to (choose from list theWorkspaces with prompt "Load this workspace" default items "None" OK button name {"Load"} cancel button name {"Cancel"})
if mychoice is not false then
set theSelection to item 1 of mychoice
close every think window
load workspace theSelection
end if
end try
end tell
This script can be paired with the following script, which will save your workspace to one of your saved ones. If you put these scripts in the tool bar, it makes it easy to load and save workspaces for individual projects, etc.
-- Save Current Workspace
-- to a list of all saved workspaces
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application id "DNtp"
try
set theWorkspaces to workspaces
set mychoice to (choose from list theWorkspaces with prompt "Save this workspace to:" default items "None" OK button name {"Save"} cancel button name {"Cancel"})
if mychoice is not false then
set theSelection to item 1 of mychoice
save workspace theSelection
end if
end try
end tell