Shoutbox

Starting an application - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Starting an application (/showthread.php?tid=70408)

Starting an application by tobias on 01-07-2007 at 05:21 AM

quote:
Originally posted by Chris Boulton
Starting a program:
var shell = new ActiveXObject("wscript.shell");
shell.Run("notepad.exe");

(Will start notepad.exe)


How would you start an application not in the default windows directory, like iTunes, XFire, FireFox, etc.?
RE: Starting an application by Ash_ on 01-07-2007 at 07:14 AM

i'm not completely sure because i usually use CreateProcess but what happens if you go like.

code:

var shell = new ActiveXObject("wscript.shell");
shell.Run("../aa.exe");


would aa.exe run (place it in the directory above the default one, usually just C:/)
RE: Starting an application by matty on 01-07-2007 at 07:15 AM

quote:
Originally posted by tobias
How would you start an application not in the default windows directory, like iTunes, XFire, FireFox, etc.?
code:
function _start_app(_path){
    new ActiveXObject('WScript.Shell').run(_path);
}

Usage:
code:
_start_app('C:\\Program Files\\iTunes\\iTunes.exe');

RE: Starting an application by tobias on 01-07-2007 at 01:52 PM

Thank you. Now to get to work! ;)

EDIT: Not working, from what I can see.


function _start_app(_path){
    new ActiveXObject('WScript.Shell').run(_path);
}
function OnEvent_ChatWndSendMessage(ChatWind,Message)
{

(There are some if statements and things here)

            if(Message=="!photoshop"){
                MsgPlus.DisplayToast("Photoshop", aMessage);
                _start_app("c:\\Program Files\\Adobe\\Photoshop CS\\Photoshop.exe");
            }
}

And it shows the taost, but doesn't launch the program, and most of the time it doesn't show up in the chat window if it starts with !, but this time it does.

P.S. I know you don't like people using ! commands, but I can't figure out how to get my commands on the / list.


RE: Starting an application by hmaster on 01-07-2007 at 02:38 PM

quote:
Originally posted by tobias
P.S. I know you don't like people using ! commands, but I can't figure out how to get my commands on the / list.

code:
function OnGetScriptCommands(){

    var ScriptCommands = '<ScriptCommands>';

         ScriptCommands += '<Command>';
         ScriptCommands += '<Name>purple</Name>';
         ScriptCommands += '<Description>Makes the window purple</Description>';
         ScriptCommands += '</Command>';

         ScriptCommands += '<Command>';
         ScriptCommands += '<Name>green</Name>';
         ScriptCommands += '<Description>Makes the window green</Description>';
         ScriptCommands += '</Command>';

    ScriptCommands  += '</ScriptCommands>';

              return ScriptCommands;
}

RE: Starting an application by tobias on 01-07-2007 at 03:32 PM

Thanks, I'll add that now. :)
Now does anyone have any ideas as to my first problem?


RE: Starting an application by foaly on 01-07-2007 at 03:34 PM

does the debugger give an error?


RE: Starting an application by hmaster on 01-07-2007 at 03:41 PM

quote:
Originally posted by tobias

Now does anyone have any ideas as to my first problem?

The problem is the spaces in the path. I don't know what to replace it with though. I've tried %20 but that didn't work.

RE: Starting an application by Eljay on 01-07-2007 at 03:52 PM

quote:
Originally posted by hmaster
quote:
Originally posted by tobias

Now does anyone have any ideas as to my first problem?

The problem is the spaces in the path. I don't know what to replace it with though. I've tried %20 but that didn't work.

you do what you normally would with a path containing spaces, put quotes around it. Which means you can either do this:
code:
new ActiveXObject("WScript.Shell").Run("\"C:\\Path Containing Spaces\"");
or to simplify things, use single quotes instead of double quotes for the string:
code:
new ActiveXObject("WScript.Shell").Run('"C:\\Path Containing Spaces"');

edit: added red highlighting to show double quotes on second example.
edit 2: updated matty's function to support paths containing spaces:
code:
function _start_app(_path){
    new ActiveXObject('WScript.Shell').run('"' + _path + '"');
}

RE: Starting an application by hmaster on 01-07-2007 at 03:55 PM

Thanks for that (Y).


RE: Starting an application by deAd on 01-07-2007 at 03:57 PM

It looks like what you're trying to do is run programs based on commands?

This can already be done with the /run command and a quicktext :P


RE: Starting an application by hmaster on 01-07-2007 at 04:03 PM

Or maybe he's making a customizable list where you can add programs for you to quickly open *-).


RE: RE: Starting an application by deAd on 01-07-2007 at 04:07 PM

quote:
Originally posted by hmaster
Or maybe he's making a customizable list where you can add programs for you to quickly open *-).

Yes but that's also quicktext-able, just add a quicktext. For example, if you want to run notepad when you type "/notepad", just make a quicktext that sends "/run notepad" when you send "/notepad"...
RE: Starting an application by tobias on 01-08-2007 at 01:32 AM

Okay, I was able to get iTunes to work with this:

_start_app('C:\\Program Files\\iTunes\\iTunes.exe');

but Photoshop won't:

_start_app('C:\\Program Files\\Adobe\\Photoshop CS\\Photoshop.exe');

Any ideas why?


RE: RE: Starting an application by CookieRevised on 01-08-2007 at 08:09 AM

quote:
Originally posted by tobias
Okay, I was able to get iTunes to work with this:

_start_app('C:\\Program Files\\iTunes\\iTunes.exe');

but Photoshop won't:

_start_app('C:\\Program Files\\Adobe\\Photoshop CS\\Photoshop.exe');

Any ideas why?

read the replies:
especially http://shoutbox.menthix.net/showthread.php?tid=70...d=775535#pid775535

But also note:
quote:
Originally posted by deAd
It looks like what you're trying to do is run programs based on commands?

This can already be done with the /run command and a quicktext :P


-----------------------------------------------------

quote:
Originally posted by tobias
P.S. I know you don't like people using ! commands, but I can't figure out how to get my commands on the / list.
This is a very big misconception...

Both things (having "/" commands, and showing up your commands in the command list window) have got nothing todo with eachother. It is not because your commands are listed in the command list window that they are reconized by Plus! as commands. And vice versa, it is not because your script handles some "/" commands that they are listed in the command list window.

The command list window is nothing more than a list of some text, nothing else.

Again: both things are totally unrelated.

- You can list whatever you want in the command list window using the OnGetScriptCommands() function (though, the text will always be prefixed with "/", eventhough you use "!").

- You can catch whatever you want to trigger something in the ChatWndSendMessage event.

Please read the documentation before you start to script, and use it regulary during scripting to look things up. Even for stuff you take for granted. And especially when people give you example code: look up every used statement, function and used method before you implement it so that you fully understand what it does, what it can't do, why it is used and what the implications are. Copying from others will also mean you could copy possible errors...

;)

---

To list commands in the command list window, see hmaster's post (and the scripting documentation).

To use proper "/" commands instead of "!" commands, do as you normally would. There is absolutely no difference at all*!!! (and see the scripting documentation).

* And that is to be taken literally. There is no difference.
A properly written ChatWndSendMessage() function should always return an empty string if a command is parsed and handled by your script. No matter how it is formatted, what command you use, what prefix you use or whatever else. Thus this goes for "!" commands too... hence why there is no difference at all.
RE: Starting an application by tobias on 01-08-2007 at 04:46 PM

I have read the replies, and they both contain spaces, which is why I'm confused. I did read most of the documentation. I am using ChatWndSendMessage(). I'm not currently on my computer, I'm on a laptop at school with a broken spacebar, so sorry if I missed the spacing on any words.

On a side note, either I am not handling commands correctly, or they are not returned empty. I'll read that section again.

EDIT: The documentation is blocked at the school, so it will have to wait until I get home. :(