Modify "Select workspace" action?

I’m big fan of Select Workspace | Drafts Action and wonder if it possible to show only workspaces which contains specific query? e. g. Scripting?
So I can only choose from for example: “scripting regex”, “scripting AppleScript” etc.
Or maybe there is another method to quickly show list of specific workspaces?

As always thank you for great support!

Hey. Try this:

https://actions.getdrafts.com/a/1gs

Should work for you out of the box if “scripting” is the actual keyword you need. Bear in mind that it’s case sensitive, so if you actually need “Scripting” rather than “scripting”, the script will need an edit.

I placed the appropriate variable at the top of the script so you can edit it easily without wading through code, but if you’re interested: all I did was wrap the bit of code that generates buttons for each workspace in a conditional statement that means buttons are only generated for workspaces that contain your desired keyword (look for the variable “filter”) in them.

Hope that helps. Holler if any probs.

4 Likes

Amazing! Works like I expected.
Appreciate your explanation. I trying to get familiar with javascript by modify actions from directory and trying to understand how it all works together.
Both in your script and other on this forum, some times on the top of script is this line: “let f = () => {” silly question, but what it does? At the end of script is: “if (!f()) {
context.cancel();”

Also if you press nothing, action will be canceled?

I get error. Duplicated action to double check and tried different filters. Created new workspace and it appears alone in prompt which is right. I press and instead opens Workspace which is first in my real workspace list and it is “lists”. Tried with another one where I get two Workspaces to choose from. If I press first workspace, it opens “lists” workspace again, if I press alternative 2, it opens second workspace of my workspaces which is “templates”

I get correct names in prompt, but end up with wrong workspace after activation

That’s one of the ways you can define and call a function in JavaScript.

If then function does not return a true, it will set the context to cancel.

Try this version.

https://actions.getdrafts.com/a/1gt

The previous version above is only filtering the list for the addition of the buttons to the prompt. It then chooses from the unfiltered list of workspaces. The version I’ve posted here addresses that.

I’ve also put the filter string into a custom tag so it can be set before the code, and added some code in to make the matching case insensitive. The content I left in there was “Gg” to match two of my workspaces for testing - “Blogging” and “tagged”.

Hope that helps.

Yes, now it loads the right workspace.

I need to learn more about js. Last week I used several hours to modify one of Greg actions for my needs. First I solved it with Keyboard Maestro, but after few minutes I thought what about my iPad? So was able to make it javascript only few hour later.
I guess if you take a look on script, you will cry because it is not elegant solution at all. However I was happy that I got it to work :blush:

Ah— my bad. Apologies. But I see @sylumer got here before me… :wink: