Drafts Action Directory

Run from external script

Posted by @davenicholls, Last update 26 days ago

Runs an action based on a JavaScript file stored in iCloud.

The action must be duplicated and renamed before use. This is because on first use it prompts for the script file to be run and then saves it for future use in a credential named based on the action name.

Subsequent uses load the script name from the credential automatically.

Note: the filename is used as is. Simple filenames (e.g. test.js) are assumed to be in the Drafts root iCloud folder. If the file is in a subfolder give the complete path (e.g. /Scripts/test.js)

Install

Steps

  • script

    if (action.name != "Run from external script") {
    
    	var credential = Credential.create("Script action: "+action.name,"Script name credential");
    	credential.addTextField("scriptFile", "Script File Name");
    	var result = credential.authorize();
    	scriptFile = credential.getValue("scriptFile");
    	
    	var db = FileManager.createCloud();
    
    	var script = db.read(scriptFile);
    
    	if (script) {
       	eval(script);
    	}
    	else {
       	console.log(db.lastError);
       	alert("Couldn't load script");
       	context.fail();
       }
       
    }
    else {
    
    	alert("Please copy and rename this script before use");
    	context.fail();
    
    }
    
    

Options

  • After Success Default
    Notification Info
    Log Level Info

Comments

Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.