Konfabulator provides two very useful functions which allow you execute to Unix commands; runCommand() and runCommandInBg(). On the Mac platform you can use any command that you could use in a terminal window. On Windows you are a little more limited because unlike on the Mac platform Windows doesn't natively understand Unix commands but fortunately Pixoria (now Yahoo) have packaged a number of the most commonly used Unix commands to the Windows version of Konfabulator.
The commands which can be used on both platforms are:
The first of these functions, runCommand() will execute a command in a blocking (synchronous) fashion, halting execution of the Widget code until the Unix command has completed and return the result of the command as a string. It's syntax is:
runCommand(string);
Where string is the command you want to execute. An example of a how you might use it is:
//Make a folder called "New Folder" on the Desktop log('Result of mkdir command: ' + runCommand('mkdir -p "' + system.userDesktopFolder + '/New Folder"'));
The second function, runCommandInBg() will execute a command in a non-bloking (asynchronous) fashion, allowing the Widget code to continue before the command has completed. When the command is completed, the globabl onRunCommandInBgComplete event is fired which will provide the result of the command. It's syntax is:
runCommandInBg(string, tag);
Where string is the command you want to execute and tag is the name of a variable (passed to the function as a string) which you define that will be populated with the result of the command when the onRunCommandInBgComplete event is fired. When the onRunCommandInBgComplete event is fired system.event.data is also populated with the name of the tag parameter relating to the runCommandInBg() call which has just completed. An example of how you might use it is:
[XML in .kon file]: <action trigger="onRunCommandInBgComplete"> if (system.event.data == 'strMkdirReturn') { log('Result of mkdir command: ' + strMkdirReturn); } </action> [Javascript in .js file or <action> block] var strMkdirReturn = ; //Make a folder called "New Folder" on the Desktop runCommandInBg('mkdir -p "' + system.userDesktopFolder + '/NewFolder"', 'strMkdirReturn');
It is also worth noting that you can string multiple Unix commands together by separating them with a semicolon (;) and execute them in a single operation like this:
//Make a folder called "New Folder" on the Desktop and rename it to "My Folder" log('Result of mkdir command: ' + runCommand('mkdir -p "' + system.userDesktopFolder + '/New Folder"; mv "' + system.userDesktopFolder + '/New Folder" "' + system.userDesktopFolder + '/My Folder"));