How to update the DP filename as personal Msg - 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: How to update the DP filename as personal Msg (/showthread.php?tid=88535)
How to update the DP filename as personal Msg by tantiger on 01-18-2009 at 02:38 PM
Hi,
I am using the DP change script to show some pictures in a certain folder. I am trying to display the filename as personal message whenever the image is changed.
I tried using Messenger.MyPersonalMessage=fileName; but it shows the full path info, when I tried to use substring,
tmpString=Messenger.MyPersonalMessage.subString(35); //skip first 35 chr
Messenger.MyPersonalMessage=tmpString;
it can only update once when I save the script, then it just leave the message empty and only update when the image is going to change, which is too short to see the name.
What I want to is, if the file name is like D:\My Picture\...\file001.jpg, how can I show file001 only as the personal message when the images are chaning in 10s interval. Can anyone help me for that? Thanks in advance.
RE: How to update the DP filename as personal Msg by matty on 01-18-2009 at 02:59 PM
Best way to do it would be
js code: Messenger.MyPersonalMessage = filename.substring(filename.lastIndexOf('\\')+1);
RE: How to update the DP filename as personal Msg by tantiger on 01-18-2009 at 03:55 PM
Hi, Matty,
I tried your method, it was suppose to work, but very strange, the name never update as fast as the picture goes. I used the following code to check if the name transferred out:
Messenger.MyDisplayPicture = fileName;
Messenger.MyPersonalMessage=fileName;
tmpString =Messenger.MyPersonalMessage;
tmpString =tmpString.substring(tmpString.lastIndexOf('\\')+1);
tmpString =tmpString.substring(0,tmpString.length-4);
MsgPlus.DisplayToast("",tmpString);
The result is, say, I have file001.jpg to file100.jpg to be displayed, when the imaged changed from 001 to 002, the tmpString can only get the old filename, file001, but the msn personal message can have the correct one but with full path.
I really confused by these codes, maybe it is due to beta version?
RE: How to update the DP filename as personal Msg by Danny22 on 01-18-2009 at 07:16 PM
I tried to make a small script for you right now but I am not sure if it's exactly what you're looking for and if it works the same way with your version of WLM.
At least with my version of WLM (8.5), you get the DP file name from the "shell:Local AppData\Microsoft\Messenger\<e-mail>\ObjectStore\UserTile" folder and an example file name could be "dW0VZfrFH4igpqB+aknu+YLVPQc=.dt2" (this is the default chess picture).
This script detects when your DP has changed and will then set your personal message as the file name ("dW0VZfrFH4igpqB+aknu+YLVPQc=" in my example).
I hope you can use it.
code: var prevDpFileName = "";
function OnEvent_Initialize(MessengerStart)
{
oldDpFileName = Messenger.MyDisplayPicture;
MsgPlus.AddTimer("DpChangeTimer", 1000);
}
function OnEvent_Timer(TimerId)
{
switch (TimerId)
{
case "DpChangeTimer":
if (Messenger.MyDisplayPicture != prevDpFileName) // your DP has changed
{
// fire custom event
OnEvent_DpChanged(Messenger.MyDisplayPicture);
prevDpFileName = Messenger.MyDisplayPicture;
}
MsgPlus.AddTimer(TimerId, 1000);
break;
}
}
function OnEvent_DpChanged(NewFileName)
{
var tempFileName = NewFileName;
// extract the file name
tempFileName = tempFileName.substr(tempFileName.lastIndexOf("\\") + 1);
var extPos = tempFileName.lastIndexOf(".");
if (extPos >= 0) // the file name has an extension
{
// remove the extension
tempFileName = tempFileName.substr(0, extPos);
}
// update personal message
Messenger.MyPersonalMessage = tempFileName;
}
RE: How to update the DP filename as personal Msg by tantiger on 01-19-2009 at 02:49 AM
Hi, Danny,
Thanks for your help. Learned something from you code
However, this filename is not I want, I am using DP change script, in that script, there is one sentence to change the DP:
Messenger.MyDisplayPicture = fileName;
What I want is to update the personal message at the same time, but it seems what I tried so far can only update the filename of the previous images, always one image behind. Really strange. I used :
Messenger.MyPersonalMessage=fileName;
tmpString =Messenger.MyPersonalMessage;
tmpString =tmpString.substring(tmpString.lastIndexOf('\\')+1);
tmpString =tmpString.substring(0,tmpString.length-4);
MsgPlus.DisplayToast("",tmpString);
immediately aft that sentence, but it seems fileName is the current new picture, while my tmpString can only have the old filename. I knew this because the last sentence showed the tmpString in toast window and my personal message is showing the correct filename with full path. Really headache, is it due to the personal message change cannot be so quick?
RE: How to update the DP filename as personal Msg by Jesus on 01-19-2009 at 03:27 AM
Let me get this straight...
fileName contains the full path to the new image.
you want to set your PSM to the name of the file in fileName
if so, use something along these lines: (can't test atm because I'm on a linux machine, but it should work)
js code: Messenger.MyPersonalMessage=fileName.substring(fileName.lastIndexOf('\\')+1, fileName.lastIndexOf('.'))
edit: lol turned into a bunny
edit2: just saw you tried matty's code (which does the same, except it doesn't remove the extension) and it delayed the PSM change... how long is the delay there?
RE: How to update the DP filename as personal Msg by tantiger on 01-19-2009 at 08:15 AM
Hi, Jesus
the fileName in the original code is not a string, so substring method not working directly on it. That's why I first let MyPersonalMessage=fileName, which works fine except it shows the full path info; then I use the tempString to get this info out and remove the path and extension.
My problem is, if I do this way, the tempString always showing the last image's filename instead of the recent one being showed.
Matty's code is showing some names as dW0VZfrFH4igpqB+aknu+YLVPQc=.dt2, which is not what I want to show. I just wondering why it always showing the last image filename instead of the current one:
Messenger.MyPersonalMessage=fileName;
tempString=Messenger.MyPersonalMessage;
After these two codes, tempString is the name of the last image while my messeger's persnal message shows the correct filename (full path). Hi, Matty, Danny22 and Jesus,
Thank you all for you help. I have figured out how to do that.
Just a force type conversion, let tempSting=String(fileName), then the script is running as what I am expecting
Thanks!
RE: How to update the DP filename as personal Msg by Jesus on 01-19-2009 at 02:12 PM
quote: Originally posted by tantiger
the fileName in the original code is not a string, so substring method not working directly on it.
wait...what??
what is it then?
I thought Messenger.MyPersonalMessage had to be set to a string?
RE: How to update the DP filename as personal Msg by tantiger on 01-19-2009 at 03:04 PM
I am also confused by the original scripts, it is from Display Picture Changer, the newest version, I would like to display the picture's filename, too, so my friends knows what that picture is. Then I tried to modify the code and found that line. I tried use that line:
Messenger.MyPersonalMessage=fileName;
Although fileName is not a pure string object, it seems it works fine. But cannot get substring from it.
RE: How to update the DP filename as personal Msg by Jesus on 01-19-2009 at 03:46 PM
I just did some research on the web, turns out fileName is a misleading name for the variable.
It's actually a File Object, obtained by enumerating a Folder Object from the FileSystem ActiveX.
Anyway, you can get its filename by using
js code: Messenger.MyPersonalMessage=fileName.Name
I'm not sure wether that includes the extension or not (still on linux), but I think it does. You can remove the extension with the substring method, as fileName.Name should be a string.
RE: How to update the DP filename as personal Msg by Danny22 on 01-19-2009 at 06:39 PM
I tried to look into the code of Display Picture Changer script (v1.2?), and I hope this is what you are looking for.
Please open the Display Picture Changer script file and do the following changes.
1. In the function ChangeDp, after the code
code: Messenger.MyDisplayPicture = fileName;
add the following:
code: UpdatePsm(fileName.Path);
2. Add the following code at the bottom of the script:
code: function UpdatePsm(NewFileName)
{
var tempFileName = NewFileName;
// extract the file name
tempFileName = tempFileName.substr(tempFileName.lastIndexOf("\\") + 1);
var extPos = tempFileName.lastIndexOf(".");
if (extPos >= 0) // the file name has an extension
{
// remove the extension
tempFileName = tempFileName.substr(0, extPos);
}
// update personal message
Messenger.MyPersonalMessage = tempFileName;
}
RE: How to update the DP filename as personal Msg by Jesus on 01-19-2009 at 07:04 PM
quote: Originally posted by Danny22
code: UpdatePsm(fileName.Path);
code: function UpdatePsm(NewFileName)
{
var tempFileName = NewFileName;
// extract the file name
tempFileName = tempFileName.substr(tempFileName.lastIndexOf("\\") + 1);
var extPos = tempFileName.lastIndexOf(".");
if (extPos >= 0) // the file name has an extension
{
// remove the extension
tempFileName = tempFileName.substr(0, extPos);
}
// update personal message
Messenger.MyPersonalMessage = tempFileName;
}
...which essentially does the same as
js code: Messenger.MyPersonalMessage = fileName.Name.substring(0, fileName.Name.lastIndexOf("."))
back on windows, so it's tested this time
RE: RE: How to update the DP filename as personal Msg by Danny22 on 01-19-2009 at 08:31 PM
quote: Originally posted by Jesus
...which essentially does the same as
js code: Messenger.MyPersonalMessage = fileName.Name.substring(0, fileName.Name.lastIndexOf("."))
back on windows, so it's tested this time
Sorry but that is not completely correct.
A file does not have to have an extension (.xxx).
lastIndexOf() will return -1 if there is no period in the string.
This leaves us with substring(0, -1), which will return "".
If I should further explain why I wrote the code that way, I will do so...
The reason why I used a new function, is to seperate your custom code from the original code as much as possible. It is easier for you to make changes that way.
You can of course use fileName.Name instead, because it does not really matter which one you use in this case.
However, by using fileName.Path, you can use both the full path (NewFileName) and just the name (tempFileName) in your own code without making any changes if you somehow want to do something with both.
I like clean and reliable code.
To make it extra clean, you could even put your own code in new files if there is a lot of code.
Please correct me if I am mistaken about anything.
RE: How to update the DP filename as personal Msg by Jesus on 01-20-2009 at 02:06 AM
quote: Originally posted by Danny22
Sorry but that is not completely correct.
A file does not have to have an extension (.xxx).
lastIndexOf() will return -1 if there is no period in the string.
This leaves us with substring(0, -1), which will return "".
In general, this is correct.
However, the populateDp() function in the script already checks that only files with a jpg, gif, bmp or png extension are added to the array. So in this case you won't encounter filenames without an extension.
quote: If I should further explain why I wrote the code that way, I will do so...
The reason why I used a new function, is to seperate your custom code from the original code as much as possible. It is easier for you to make changes that way.
You can of course use fileName.Name instead, because it does not really matter which one you use in this case.
However, by using fileName.Path, you can use both the full path (NewFileName) and just the name (tempFileName) in your own code without making any changes if you somehow want to do something with both.
Again, correct, but only IF you want to do something with the path. If not, it's basically a waste of CPU cycles (not that you'd notice it on most modern systems). The topic starter just wanted to get rid of the full path, so why get the full path and cut the folders off if you can get the filename with another method?
Also, if you want the path afterwards for another reason, there's still the File Object (fileName) to get the full path from in the way you did.
quote: I like clean and reliable code.
To make it extra clean, you could even put your own code in new files if there is a lot of code.
I have to say, I like clean code too.
I just don't really see how it's cleaner to add an extra function if everything that function does can be done in a single statement too.
quote: Please correct me if I am mistaken about anything.
It's not that you're mistaken about anything, for all I know your code works ok (haven't tested though). It's just that we seem to have a different idea on code organizing and efficiency.
RE: How to update the DP filename as personal Msg by Danny22 on 01-20-2009 at 10:31 AM
quote: Originally posted by Jesus
However, the populateDp() function in the script already checks that only files with a jpg, gif, bmp or png extension are added to the array. So in this case you won't encounter filenames without an extension.
Oh, I see. If I knew that, I would have made it in just one line like you did, and made a new function if I wanted to add more to it.
I'm not using this an excuse, but I only tried to figure out how to use the fileName variable, and worked from there.
Topic starter: I already gave you a solution which should work, but also I suggest that you use Jesus' code. I am sure you have already figured out by now the best way for you to do it though.
RE: How to update the DP filename as personal Msg by tantiger on 01-20-2009 at 01:50 PM
Yes, thanks a lot for the discussion from you all. Really appreciate that. Both are good. I think the original DP changer not perfect, say, when u put appear offline, it won't detect that and continue changing pictures. I am trying to have my own version, can update picture and filename at the sametime or not showing the filename when I uncheck one option. And when appear offline, it will be silent I have somehow finished the script, now after your comments, cleaner code, hmm, I need more time, haha.
Have a nice day! Thank you all!
|