I use the Workspace command a lot, but I’m always hunting for the menu, or forget which key command I assigned to a specific workspace. So I wanted a button in the toolbar that would give me quick access to any of my workspaces. I made this quick little script, and saved in into the Scripts > Toolbar folder:
tell application id "DNtp"
try
set theWorkspaces to workspaces
choose from list theWorkspaces
if the result is not false then
set theSelection to item 1 of the result
load workspace theSelection
end if
end try
end tell
But as I said, yours is actually more useful to teach people basic AppleScript. You can go line-by-line or block-by-block and discuss each part individually.
Mine is fun but harder to read (or maybe grasp) for the n00bs.
Hmm, just realized that the script (either version!) creates a new window, instead of switching the workspace used in the current window. So if you keep running it, you get window after window…
Can the “load workspace” command be targeted to the current window?
Jim do you have a script list(your personal) somewhere that anyone can use?
You mean scripts I’ve written or use?
PS: The one-liner is a personal challenge to me, but not something I think everyone should strive for, especially in the beginning. The Achilles heel of one-liners is it doesn’t allow for error-trapping so the conditions have to be just right to pull it off.
Many of my scripts are internal proofs-of-concept, explorations, or one-off solutions for customers. A quick search of my Coding folder yields 744 scripts. (Note: Some of these would be what I refer to as scriptgrounds, test chunks of code or previous iterations before refactoring.)
Okay that is super handy and cool. (By the way, @BLUEFROG, I went ahead and bought Sal S.'s book 1-2-3 Applescript based on our discussions on this forum).
Question: how do I give an AppleScript in the Toolbar a nicer icon?
(By the way, @BLUEFROG, I went ahead and bought Sal S.'s book 1-2-3 Applescript based on our discussions on this forum)
Nice! Sal is the Man, for sure. He and Shane Stanely are giants in Mac automation.
(By the way, @BLUEFROG, I went ahead and bought Sal S.'s book 1-2-3 Applescript based on our discussions on this forum)
You can change the icon for the script in the Finder, but currently it will be bounded in a button. Like so…
@cgrunenberg would have to assess whether this can be changed to allow for just displaying the icon itself. (I’m guessing it would not be a simple change.)
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
In this forum, u can ask for anything and very likely will be getting a response. FYI, I also didn’t know where to place a script and not even understand what a script is about 18 months ago.
For putting script under the toolbar menu, see pg 179-180 of the manual. Just remember to quit and re-open DT3 AFTER you place the script in the folder. The customisation of button is mostly similar to other app, ctrl-click the toolbar and you see a list of buttons for drag and drop on to the toolbar.
Also even if you aren’t on DevonThink, combined with bring DT front and your script, this script brings DT front then brings window to choose workspaces.
activate application "DEVONthink 3"
tell application "System Events"
tell process "DEVONthink 3"
try -- Symbols
set focused of scroll area 1 of group 1 of splitter group 1 of splitter group 1 of window 1 to true
end try
try -- List
set focused of outline 1 of scroll area 1 of group 1 of splitter group 1 of splitter group 1 of window 1 to true
end try
try -- Columns
set focused of scroll area -2 of scroll area 1 of browser 1 of splitter group 1 of group 1 of splitter group 1 of splitter group 1 of window 1 to true
end try
try -- Two pane
set focused of outline 1 of scroll area 1 of splitter group 1 of group 1 of splitter group 1 of splitter group 1 of window 1 to true
end try
try -- Three pane / Tags
set focused of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of group 1 of splitter group 1 of splitter group 1 of window 1 to true
end try
end tell
end tell
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