Javascript Macro Does Not Seem to Work

54 views
Skip to first unread message

Patrick Aquilone

unread,
Feb 17, 2017, 6:36:33 PM2/17/17
to TiddlyWiki
Hello,

So I created the following macro:

/*\
title: $:/macros/runProgram
type: application/javascript
module-type: macro

<<runProgram program parameters>>

Example:
<<runProgram '\"C:\\Program Files (x86)\\PuTTY\\putty.exe\"' >>
<<runProgram '\"C:\\Program Files (x86)\\PuTTY\\putty.exe\"' '-ssh -X'>>

\*/
(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

/*
Information about this macro
This is written to have a javascript run a windows program  
*/

exports.name = "runProgram";

exports.params = [
{ name: "program" },
{ name: "parameters" }
];

/*
Run the macro
*/
exports.run = function(program, parameters) {
   alert(program + " " + parameters);
if( !program) return false;
if( !parameters) parameters = "";
    var shell = new ActiveXObject("WScript.Shell");                 
    var cmd = program + " " + parameters;
    shell.Run(cmd);
return true;
};

})();

I added the tag $:/tags/Macro and have it defined as $:/macros/runProgram (actual link file:///H:/PRAQUILONE/TiddlyWiki/PatCave.html#%24%3A%2Fmacros/runProgram).

Now this, if it would actually work inside of TW, would call out to shell and run an external windows program.  As an example, I would pass it the path and executeable to PuTTy and the IP address I want it to connect too.

I would like to have this where on another Tiddler, I have a link that calls this macro and passes it the program and the parameters (like Putty and "10.0.0.1" or whatever) and have it launch putty.  This javascript code will work if I make it a function inside an HTLM script tag and call in in from the anchor link as the href and launches the program.  I am hoping I can do the same.  But whenever I try to use this macro nothing happens.  Not sure if I messed up making or missed a step or what.

Would appreciate any help.

Thanks

PMario

unread,
Feb 17, 2017, 6:48:45 PM2/17/17
to TiddlyWiki
Hi Patrick,

This is IE only and if it works, imo, it's super dangerous. see: https://msdn.microsoft.com/ro-ro/library/7sw4ddf8(v=vs.94).aspx

JavaScript is run in a sandboxed VM for a reason. Having full access to the underlying OS only hurts.

-mario

Patrick Aquilone

unread,
Feb 17, 2017, 7:47:23 PM2/17/17
to TiddlyWiki
I am open to alternative methods.  I had originally tried the window.open(url) but it didn't like the command line parameters that I need to send.  So I researched and found this way.
Reply all
Reply to author
Forward
0 new messages