Action

Run from external script

Posted by @davenicholls, Last update about 6 years 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)

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
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.