Drafts Action Directory

Piques - Ask & Insert

Posted by @nahumck, Last update 3 months ago

Create a “Piques of the Week” post. Opens a search to get the latest number, and then prompts for the number and the items (up to 3) that are to be included in the post.

Install

Steps

  • script

    // Piques Post Template Script
    // Action by nahumck
    
    // Search URL
    var url = "http://nahumck.me/?s=piques";
    
    // Create template variables
    var p1 = "";
    var p2 = "";
    var p3 = "";
    var ret = "\n";
  • script

    // Open search URL in the Drafts SVC
    var result = app.openURL(url, true);
  • script

    //Display Prompt
    var p = Prompt.create();
    p.title = "Enter Piques Post Information";
    p.addTextField("pNum", "Piques #", "", {placeholder:"99",keyboard:"numberPad"});
    p.addTextField("pique1", "Pique 1", "", {"autocapitalization":"sentences","placeholder":"thing 1"});
    p.addTextField("pique2", "Pique 2", "", {"autocapitalization":"sentences","placeholder":"thing 2"});
    p.addTextField("pique3", "Pique 3", "", {"autocapitalization":"sentences","placeholder":"thing 3"});
    p.addButton("Go");
    var con = p.show();
    
    if (con) {
      var num = p.fieldValues["pNum"];
      var pique1 = p.fieldValues["pique1"];
      var pique2 = p.fieldValues["pique2"];
      var pique3 = p.fieldValues["pique3"];
    
      // Create template
      var ptitle = "# Piques of the Week - Volume "+num+ret+ret;
      var p1 = "## "+pique1+ret+ret+"["+pique1+"]()"+ret+ret+ret;
      if (pique2.length > 0) {
        var p2 = "## "+pique2+ret+ret+"["+pique2+"]()"+ret+ret+ret;
      }
      if (pique3.length > 0){
        var p3 = "## "+pique3+ret+ret+"["+pique3+"]()"+ret+ret+ret;
      }
      var d = Draft.create();
      d.content = ptitle+p1+p2+p3;
      d.update();
      editor.load(d);
    }
    else {
      context.cancel();
    }

Options

  • After Success Default
    Notification Info
    Log Level Error

Comments

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