Drafts Action Directory

Search DDG

Posted by @nahumck, Last updated: 2018-07-03 22:57:14 UTC

Search on DuckDuckGo with an optional !bang parameter.

!bangs can be found at:
https://duckduckgo.com/bang

Install

Steps

  • script

    //DDG Search (w/ !bangs)
    
    var content = draft.processTemplate("[[selection]]")
    
    var p = Prompt.create();
    p.title = "Enter search and optional !bang";
    p.addTextField("search", "Search", content);
    p.addTextField("bang", "!bang", "", {placeholder:"eg. !g, !images, etc."});
    p.addButton("Go");
    var con = p.show();
    
    if (con) {
      var input = p.fieldValues["search"];
      var output = encodeURIComponent(input);
      var bang = p.fieldValues["bang"];
    
      if (bang == "") {	
        var searchBang = "!ddg";}
      else {
        var searchBang = bang;
      }
      var url = "https://duckduckgo.com/?q="+searchBang+"%20"+output;
      var result = app.openURL(url, true);
    }
    else {
      context.cancel();
    }

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.