Run Editor JS

Posted by RoyRogers, Last update 25 days ago

Runs a script diretly from Drafts editor.

Note! Be careful:
If your script updates current content, it may mess itself up.

Use during development and debuging, with full use of Drafts versioning, tools, and actions.

Then copy draft into action script when finalized, or modify a copy of this scipt to run JS Code in Drafts’ archive using eval with UUID as described in comments. Have fun :)

Steps

  • script

    // Run Editor JS
    // RV 2020-03-05 at 18:46 EST
    (() => {
        // Runs a script diretly from Drafts editor.
        // Note! Be careful:
        // If your script updates current content, it may mess itself up.
        // Only intended for development and debuging purposes,
        // With full use of Drafts versioning, tools and actions.
    
        // Alternative code to use with spesific script saved as drafts:
        // // UUID of draft containing script:
        // const uuid = '401B8C95-29F9-4917-8364-0D769C71EE8F';
    	try {
    		eval( // line 14.
    			draft.content
    			// Draft.find(uuid).content
    		)
    	} catch (e) {
    		if (e.line != '14') {
    			alert(`Runtim Error: ${e.message}
    		
    			line: ${e.line}
    			column: ${e.column}`)
    		} else {
    			alert(`Syntax Error: ${e.message}
    			line: ${e.line}
    			column: ${e.column}
    			Likely a syntax error, disregard line number!`)
    		}
    	}
    }
    )();

Options

  • After Success Nothing
    Notification Error
    Log Level Error
Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.