Action

URL

Posted by viticci, Last update over 6 years ago - Unlisted

Given a draft with a valid URL, this action gives you the option to re-copy it or share it with the share sheet.

Still not implemented: deal with multiple URLs.

URL regex via: http://stackoverflow.com/questions/3809401/ddg#3809435

Steps

  • script

    var expression = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi;
    var regex = new RegExp(expression);
    var t = draft.processTemplate('[[draft]]')
    
    if (t.match(regex)) {
      var url = t.match(regex)
      var p = Prompt.create();
      p.title = "Matched URL";
      p.message = url
      p.addButton("Copy");
      p.addButton("Share URL");
    
      var didSelect = p.show();
    
    
      if (p.buttonPressed == "Copy") {
        app.setClipboard(url)
      }
      else if (p.buttonPressed == "Share URL") {
        var d = Draft.create()
        d.content = url
        var a = Action.find("Share Sheet");
        app.queueAction(a, d);
      }
    } 
    
    else {
        alert("No URL found.");
    }

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.