Action

action runner

Posted by FlohGro, Last update 5 days ago

created by @FlohGro / more on my Blog

action runner

Configure an action group and define actions that shall be included or excluded and this action will present you a prompt to select one from the resulting actions. It will run the action afterwards.

This is useful for the action bar or an action group where you want to combine different actions without making several aliases of them.

[Configuration]

The action uses the newly introduced (January 2025) “Configure Value” steps. The first time you run the action you will see a prompt that asks you to configure the following values:

  • Action Group Name (required): add the exact name of the Action Group
  • Include Action Names (optional): add names of actions that you want to explicitly include (all others will be ignored)
  • Omit Action Names (optional): add names of actions that you want to explicitly exclude (all others will be included)

please note: if you configure both Include and Omit Action Names, only the Include Action Names will be considered.

If you want to change you’re configuration, long press / right click on the action and select “Configure,…” and the configuration prompt will appear again.


If you find this useful and want to support me you can donate or buy me a coffee

Steps

  • configurationKey

    name
    Action Group Name
    key
    actiongroupname
  • configurationKey

    name
    Include Action Names (optional)
    key
    includeactionname
  • configurationKey

    name
    Omit Action Names (optional)
    key
    omitactionname
  • script

    // action runner created by @FlohGro@social.lol
    
    // get inputs
    const actionGroupName = context.configuredValues["actiongroupname"].trim()
    // i need to make sure there are no elements with empty strigs
    const actionNamesToInclude = context.configuredValues["includeactionname"].trim().split(",").filter((a) => a.length > 0)
    const actionNamesToOmit = context.configuredValues["omitactionname"].trim().split(",").filter((a) => a.length > 0)
    
    if (actionNamesToInclude.length > 0 && actionNamesToOmit.length > 0) {
        console.log("action is configured to include and omit actions, using include actions is explicit, so only the mentioned actions will be included anyways.")
    }
    
    
    // function to get action group (or undefined)
    function getActionGroup() {
        return ActionGroup.find(actionGroupName);
    }
    
    function getActions(actionGroup) {
        let actions = actionGroup.actions
        // remove separators
        actions = actions.filter((a) => !a.isSeparator)
    
        if (actionNamesToInclude.length > 0) {
            actions = actions.filter((a) => {
                const actionName = a.name
                if (actionNamesToInclude.includes(actionName)) {
                    return true
                }
                return false
            })
        }
    
        if (actionNamesToOmit.length > 0) {
            actions = actions.filter((a) => {
                const actionName = a.name
                if (actionNamesToOmit.includes(actionName)) {
                    return false
                }
                return true
            })
        }
        return actions
    
    }
    
    function runActionFromPrompt(actions) {
        let p = new Prompt()
        p.title = "select action"
        actions.forEach((a) => {
            p.addButton(a.name, a)
        })
        if (p.show()) {
            let selectedAction = p.buttonPressed
            app.queueAction(selectedAction, draft)
        }
    }
    
    const actionGroup = getActionGroup();
    if (actionGroup) {
        const actions = getActions(actionGroup)
        if (actions) {
            runActionFromPrompt(actions)
        }
    
    } else {
    	console.error("no action group with name \"" + actionGroupName + "\" found.")
    	alert("No action group with name \"" + actionGroupName + "\" found.\n\nPlease run the configuration again.")
    }
    

Options

  • After Success Default
    Notification Error
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.