Shoutbox

Help running application on initialize - 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: Help running application on initialize (/showthread.php?tid=70793)

Help running application on initialize by Jimbo on 01-17-2007 at 08:29 PM

Why doesn't the following code work for me. Debug says unterminated string constant

code:
function OnEvent_Initialize(MessengerStart)
{
new ActiveXObject("WScript.Shell").Run("\"C:\\Program Files\Windows Media Player\wmplayer.exe"");
}
}

RE: Help running application on initialize by matty on 01-17-2007 at 08:30 PM

All \ in Javascript need to be \\.

code:
function OnEvent_Initialize(MessengerStart) {
    new ActiveXObject('WScript.Shell').run('\\C:\\Program Files\\Windows Media Player\\wmplayer.exe');
}

RE: Help running application on initialize by Jimbo on 01-17-2007 at 08:31 PM

quote:
Originally posted by Matty
All \ in Javascript need to be \\.
* Jimbo hides in shame :$

Thanks!
RE: Help running application on initialize by CookieRevised on 01-17-2007 at 09:20 PM

code:
.Run("\"C:\\Program Files\\Windows Media Player\\wmplayer.exe\"");

PS: try not to run an application on initialize if possible. The function initialize must return as quickly as possible and should do as little as possible. Instead use SignInReady or use a timer.
RE: Help running application on initialize by Jimbo on 01-19-2007 at 07:03 AM

quote:
Originally posted by CookieRevised
code:
.Run("\"C:\\Program Files\\Windows Media Player\\wmplayer.exe\"");

PS: try not to run an application on initialize if possible. The function initialize must be return as quickly as possible and should do as little as possible
Thanks cookie i've changed it to OnEvent_Signin, but is there anyway to make it play automatically as well?

RE: Help running application on initialize by NanaFreak on 01-19-2007 at 07:06 AM

code:

The MsgPlus::PlaySound function plays a sound asynchronously. It can also be used to stop the current sound from playing.

[boolean] PlaySound(
    [string] SoundFile
    [number,optional] MaxPlayTime
);

;) next time read your scripting doc....

that was in Objects Reference > MsgPlus Object > functions > Play Sound



edit: sorry it wasnt what you wanted :/
RE: Help running application on initialize by Jimbo on 01-19-2007 at 07:09 AM

quote:
Originally posted by NanaFreak
code:

The MsgPlus::PlaySound function plays a sound asynchronously. It can also be used to stop the current sound from playing.

[boolean] PlaySound(
    [string] SoundFile
    [number,optional] MaxPlayTime
);

;) next time read your scripting doc....

that was in Objects Reference > MsgPlus Object > functions > Play Sound
Thanks :p

EDIT: My code:
code:
function OnEvent_SigninReady(Email){
    new ActiveXObject('WScript.Shell').Run("\"C:\\Program Files\\Windows Media Player\\wmplayer.exe\"");
}

But what i want to do is when WMP runs i want to play a certain playlist and maybe even a random one each time it is run. Is this possible?
RE: Help running application on initialize by CookieRevised on 01-19-2007 at 01:30 PM

With the Run function you start up an application. Most applications can take parameters and depending on what parameters you enter it does different stuff.

This is no different for WMP. What you do with the Run function is the same as what you do when you manually start a sound or playlist in Windows Explorer. In that case Windows will also start up WMP with a parameter, being the playlist for example.

What you also can do is starting up the playlist itself instead of starting up the WMP application. Windows will then automatically start that file with the associated application, which is in this case WMP. This is your best method for something like this because then you don't need to worry about the correct parameters (which can be quite different than just adding the filename to the command line) and Windows will handle all the rest for you.

So instead of Run("c:\wmplayer.exe") you do Run("c:\myplaylist.wpl"). The script should of course handle the randomness itself and needs a list (or directory) to choose the list from.


RE: Help running application on initialize by Jimbo on 01-19-2007 at 07:33 PM

quote:
Originally posted by CookieRevised
With the Run function you start up an application. Most applications can take parameters and depending on what parameters you enter it does different stuff.

This is no different for WMP. What you do with the Run function is the same as what you do when you manually start a sound or playlist in Windows Explorer. In that case Windows will also start up WMP with a parameter, being the playlist for example.

What you also can do is starting up the playlist itself instead of starting up the WMP application. Windows will then automatically start that file with the associated application, which is in this case WMP. This is your best method for something like this because then you don't need to worry about the correct parameters (which can be quite different than just adding the filename to the command line) and Windows will handle all the rest for you.

So instead of Run("c:\wmplayer.exe") you do Run("c:\myplaylist.wpl"). The script should of course handle the randomness itself and needs a list (or directory) to choose the list from.
Thanks cookie, very useful as usual ;)

Why doesn't this code work then?
code:
function OnEvent_Signin(){
    new ActiveXObject('WScript.Shell').Run("\"C:\\Documents and Settings\\James Ross\\My Documents\\My Music\My Playlists\\Untitled Playlist.wpl\\"");
}


RE: Help running application on initialize by pedro_cesar on 01-19-2007 at 11:20 PM

'cuz u missed a \ in the route right before "My Playlist"


RE: Help running application on initialize by CookieRevised on 01-20-2007 at 01:47 AM

Because of:

quote:
Originally posted by pedro_cesar
'cuz u missed a \ in the route right before "My Playlist"

And because you end your command line with a double slash (\\) which will be interpreted as a single slash (\).

In strings, if you wish to have a single slash, you must preceed it with an escape character. In JScript (and most other similar languages) the escape character is also a slash.

Hence why you must enter double slashes everywhere where you wish to use a single slash (\).

But the last character in your command line string is not meant to be a slash, it is meant to be a quote. Quotes are also special characters since they define strings. So either you tell JScript that the following character is going to be a special character and you must proceed it with the escape character (\), or either you enclose your entire string in single quotes (which also can be used in JScript to define a string):

Thus, either:
code:
Run("\"C:\\Documents and Settings\\James Ross\\My Documents\\My Music\\My Playlists\\Untitled Playlist.wpl\"");
or:
code:
Run('"C:\\Documents and Settings\\James Ross\\My Documents\\My Music\\My Playlists\\Untitled Playlist.wpl"');
where it begins with '" which is single quote ('), double quote (") and ends in "' which is double quote ("), single quote (').

What you put as command for the Run function must be enclosed into double quotes since it can/will contain spaces. These double quotes are part of the command line and string. They do not define the string. And since this entire command line (incl. double quotes) is a string you must enclose it into (double or single) quotes too.
RE: Help running application on initialize by Jimbo on 01-20-2007 at 08:34 AM

This code still doesn't work and there is nothing in debug:

code:
function OnEvent_Signin(Email){
    new ActiveXObject('WScript.Shell').Run("\"C:\\Documents and Settings\\James Ross\\My Documents\\My Music\\My Playlists\\Untitled Playlist.wpl\"");
}

RE: Help running application on initialize by CookieRevised on 01-20-2007 at 01:28 PM

That code should work perfectly... (it does here)...

Make sure WMP is properly installed and that the association with .wpl files is valid, and that path is correct and the playlist exists.

What happens if you go to Start > Run  and you enter:
   "C:\Documents and Settings\James Ross\My Documents\My Music\My Playlists\Untitled Playlist.wpl"
?


RE: Help running application on initialize by Mike on 01-20-2007 at 01:42 PM

Try using ShellExecute.


RE: Help running application on initialize by CookieRevised on 01-27-2007 at 04:05 PM

quote:
Originally posted by Mike
Try using ShellExecute.
which means using ShellExecute with the 'open' operation, which is the exact same thing as using Run.
RE: Help running application on initialize by balabek on 04-10-2007 at 12:53 PM

Thanks a lot for this.
I have added "Music Notification" for a few contacts :).


RE: Help running application on initialize by vikke on 04-10-2007 at 01:09 PM

May I add something?

I'm quite sure you can run any program (which supports it) with the first parameter as the path to the file to be opened, and it will be opened when you run.

vikke