Drafts Action Directory

Send to iA Writer

Posted by @davenicholls, Last update 29 days ago

Sends current draft to iA Writer using the new x-callback-URL scheme

Default folder “/test/drafts” is set in the script and can be changed. Note that the folder must exist or the action will fail

Filename is set to the file safe version of the draft title

Requires auth token, which can be found in iA Writer -> Settings -> URL Commands

Install

Steps

  • script

    const baseURL = "ia-writer://x-callback-url/write/";
    const basePath = "/test/drafts/";
    
    var credential = Credential.create("IA-Writer", "IA-Writer Token");
    
    credential.addTextField("token", "Token");
    
    var result = credential.authorize();
    
    if (!result) {
    
       alert("Failed to obtain credentials. Please check and retry");
       context.cancel("Failed to obtain credentials");
    
    }
    else {
    
       // create and configure callback object
       var cb = CallbackURL.create();
       cb.baseURL = baseURL;
       cb.addParameter("auth-token", credential.getValue("token"));
       cb.addParameter("path", basePath+draft.processTemplate("[[safe_title]]"+".txt"));
       cb.addParameter("text", draft.content);
    
       var success = cb.open();
    
       if (success) {
          console.log("File created: "+ cb.callbackResponse.path);
       }
       else {
          if (cb.status == "cancel") {
             context.cancel();
          }
          else {
             context.fail(cb.callbackResponse.errorMessage);
          }
       }
    }

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.