scriptsMenu

Scripts
  Ping tagserver
    pingDavesTags () //need to replace this with script code
  Make Submenu
    //put the cursor on a headline you want to make a submenu, and choose this command
    op.attributes.setOne ("flSubMenu", true)
  This is just a test
    dialog.alert ("Oh the buzzing.")
  -
  Outlines
    visit verbs
      op.visitAll
        var ct = 0;
        op.visitAll (function (headline) {
          ct++;
          console.log (string.padWithZeros (ct, 4) + ": " + headline.getLineText ());
          return (true);
          });
      op.visitToSummit
        op.visitToSummit (function (headline) {
          console.log (headline.getLineText ());
          return (true);
          });
      op.visitSubs
        op.visitSubs (function (headline, level) {
          console.log (string.filledString ("\t", level) + headline.getLineText ());
          return (true);
          });
    get headers
      //An example script for opml.setHeadrers docs
      var headers = opml.getHeaders ();
      headers.someRandomValue = number.random (1, 1000);
      opml.setHeaders (headers);
    op.getCursor test
      var origCursor = op.getCursor ();
      op.firstSummit ();
      dialog.alert (op.getLineText ());
      op.setCursor (origCursor)
    Cursor madness
      op.firstSummit ();
      op.collapse ();
      op.expandAllLevels ();
      while (true) {
        op.expand (1);
        if (!op.go (flatdown, 1)) {
          break;
          }
        }
    Get linetext
      dialog.alert (op.getLineText ())
    Get cursor OPML
      console.log (op.getCursorOpml ())
      op.expand (1)
      op.go ("down", 1)
    Summit collapse
      op.firstSummit ();
      while (true) {
        op.collapse ()
        if (!op.go (down, 1)) {
          break;
          }
        }
    Import file test
      file.readWholeFile ("myOutlines/denton.opml", function (data) {
        op.insertOpml (data, down);
        op.go (down, 1);
        });
    HTMLize subs
      if (op.go (right, 1)) {
        var htmltext = "", indentlevel = 0;
        function add (s) {
          htmltext += s + "\n";
          }
        add (""); indentlevel++;
        add (""); indentlevel++;
        while (true) {

          add ("
          " + op.getLineText () + "
          ");

          if (!op.go (down, 1)) {
            break;
            }
          }
        op.go (left, 1);
        add (""); indentlevel--;
        add (""); indentlevel--;
        file.writeWholeFile ("test.html", htmltext, function (data) {
          webBrowser.openUrl (data.url);
          });
        }
      else {
        dialog.alert ("Please put the cursor on a headline with expanded subheads.");
        }
  Twitter
    List early users
      var flfirst = true;
      op.insert ("Early Twitter signups", down);
      for (var i = 12; i < 25; i++) {
        op.insert (twitter.getScreenname (i), (flfirst) ? "right" : "down");
        flfirst = false;
        }
      op.go (left, 1);
  Basics
    Hello world
      dialog.alert ("Hello world.");
    dialog.ask
      var yo = dialog.ask ("Prompt", "default value", "placeholder");
      if (yo === undefined) {
        dialog.alert ("You clicked Cancel.");
        }
      else {
        dialog.alert (yo);
        }
    App version
      dialog.alert (fargo.version ());
    Add numbers
      dialog.alert (12 + 34)
    Count
      var j;
      for (var i = 0; i < 10000; i++) {
        j = i * 2;
        }
      dialog.alert (i)
    Local function
      function getSomeNumber () {
        return (random (0, 1000));
        }
      file.writeWholeFile ("number.txt", getSomeNumber ())
      dialog.alert (file.readWholeFile ("number.txt"));
  Strings
    beginsWith
      dialog.alert (string.beginsWith ("my name is Bull", "my"));
    countFields
      dialog.alert (string.countFields ("/scripting.com/2003/08/12.html", "/"))
    hashMD5
      dialog.alert (string.hashMD5 ("My name Jose Jimenez."));
    trimWhitespace
      dialog.alert ("\"" + string.trimWhitespace (" It's even worse than it appears. ") + "\"");
  Files
    Write a file
      file.writeWholeFile ("tmp.txt", "oh the buzzing of the bees.")
    Read a file
      dialog.alert (file.readWholeFile ("tmp.txt"));
    Delete a file
      file.writeWholeFile ("deleteme.txt", "It's even worse than it appears.")
      file.delete ("deleteme.txt");
    Modify a file
      dialog.alert (file.writeWholeFile ("tmp.txt", string.upper (file.readWholeFile ("tmp.txt"))))
    Current file info
      dialog.alert (jsonStringify (file.getCurrentFileInfo ()))
    File list
      dialog.alert (jsonStringify (file.getFileList ()))
    File hierarchy
      console.log (jsonStringify (file.getFileHierarchy ()));
    -
    Make file public
      dialog.ask ("Here's your file:", file.makeFilePublic ("myOutlines/hello.opml"));
    View in reader
      file.viewCurrentFileInReader ();
      file.makeFileViewable (function (theUrl) {
        if (theUrl === undefined) {
          dialog.alert ("Can't open the file in the reader, possibly because it's not public.");
          }
        else {
          webBrowser.openUrl (theUrl);
          }
        })
  Errors
    Syntax error
      12 +
    Runtime error
      dialog.alert (file.readWholeFile ("mensch.txt")) //the file is not there
    Debugging test
      function buildString (s) {
        for (var i = 0; i < 100; i++) {
          s += "a";
          }
        return (s);
        }
      console.log ("hello")
      debugger; //the debugger should open? probably did in a previous version
      var s = buildString ("") ;
      console.log ("goodbye")
  Net
    Read a file over HTTP
      dialog.alert ("There are " + http.readUrl ("http://scripting.com/rss.xml").length + " chars in the Scripting News feed.")
    Get domain name
      dialog.alert (dns.getDomainName ("52.217.47.139"))
    Get dotted id
      dialog.alert (dns.getDottedId ("scripting.com"))
    Tweet
      twitter.tweet ("This is a test")
    Get Jack's tweets
      twitter.getUserTweets ("jack", function (theTweets) {
        for (var i = 0; i < theTweets.length; i++) {
          var theTweet = theTweets [i];
          console.log (theTweet.text);
          }
        });
    Post a tweet...
      dialog.confirm ("This will post a test tweet from your account.", function () {
        twitter.post ("This is a test. Please ignore. Thank you. :-)");
        });
  Tabs
    Current file path
      dialog.alert (file.getCurrentFilePath ())
    Current file title
      dialog.alert (file.getCurrentFileTitle ())
    Current file info
      dialog.alert (jsonStringify (file.getCurrentFileInfo ()))