Action
Open Random Draft from Workspace
created by @FlohGro / more on my Blog
Open Random Draft from Workspace
This action was created as one of the results of this post in the forums: Action to open random draft
It used @galtenberg’s Open Random Draft by Tag Action as inspiration.
The Action opens a random draft from the configured workspace and search scope (“all”,“inbox”,“archive”,“flagged”,“trash”).
[Configuration]
To configure the workspace and scope you need to edit the Action.
The first two “Define Template Tag” steps are the configuration options.
To configure the workspace you need to edit the first step which is the template tag “workspaceName”. Just type in the name of the workspace you want to use with this action.
The search scope defaults to “all”. If you want to change this you can edit the second step in the action and modify it to any of the following values: “all”, “inbox”, “archive”, “flagged”, “trash”. Don’t include the quotes in the template.
If you change the names of the template tags the Action will not work anymore
[Usage]
Whenever you want to e.g. reflect on a random note you have in the configured workspace just run the Action and a random draft will be loaded.
If you have several workspaces where this action might be useful, you can safely duplicate and rename the Action and use it with different workspaces.
If you find this useful and want to support me you can
Steps
-
defineTemplateTag
name workspaceName
template unconfigured
-
defineTemplateTag
name workspaceQueryScope
template all
-
script
const wsName = draft.processTemplate("[[workspaceName]]"); const wsQueryScope = draft.processTemplate("[[workspaceQueryScope]]"); let errorMsg = "" function openRandomDraft() { if(wsName == "unconfigured"){ errorMsg = "workspace name was not configured" return false; } if(!["all","inbox","archive","flagged","trash"].includes(wsQueryScope)){ errorMsg = "query scope misconfigured" return false; } let workspace = Workspace.find(wsName); if(!workspace){ errorMsg = "workspace \"" + wsName + "\" not found" return false; } const allWsDrafts = workspace.query(wsQueryScope).filter(d => d.uuid != draft.uuid) const randomDraft = allWsDrafts[Math.floor(Math.random() * allWsDrafts.length)] return randomDraft; } let draftToOpen = openRandomDraft() if(!draftToOpen){ context.fail(errorMsg) app.displayErrorMessage(errorMsg) } else { editor.load(draftToOpen) }
Options
-
After Success Nothing Notification Error Log Level Error