Wiki

Clone wiki

kbar / Buttons / Scriptlet

If you're reading this, you're probably a script author.

What is the function name/argument field for?

Some users are scared to modify code but can handle modifying a simple string value. The function/name field is a way for you to parameterize your scriptlet without needing to create UI to get the value. This is typically used more for script authors that distribute JSX(BIN) files.

If you want to use this field for your scriptlets you can use this snippet to get the value:

var button = (typeof kbar !== 'undefined') ? kbar.button : null;

if (button)
{
   var version = kbar.version;       // KBar version like '2.0.5'
   var JSON = kbar.JSON;             // Lets you stringify/parse JSON strings
   var aeq = kbar.aeq;               // Lets you use aequery

   var id = button.id;               // A randomly generated string by KBar
   var name = button.name;           // The name the user set for the button
   var argument = button.argument;   // The argument field

   switch(button.argument)
   {
      case 'Function 1': 
         doSomething(); 
         break;

      case 'Function 2':
         doSomethingElse();
         break;

      default:
         alert("I don't know what the argument " + button.argument + " is supposed to do");
         break;
   }
}
else
{
   // Run your script as normal
}

Updated