Wallpaper scripting

*Perhaps mistakingly posted to DX Support Forums ...

I am VERY new to scripting. In a way, I'd like to not have to learn it because in my current state I have a problem retaining information that is new to me. This is legitimate, and in no way do I simply want to get code for nothing and call it my own or what-have-you. But I am having a problem understanding what would seem to me a simple thing to do because I've seen it in various aspects with widgets or objects.

Please keep in mind I have searched here and various other sites on scripting, and have also read [but possibly not understood] the documentation for DX 3.1

What I would like to do is make my own desktop picture viewer that on a click of the currently displayed image would apply that image as the desktop wallpaper. Or maybe adding another object button and clicking on that to apply the image as a wallpaper.

I have modified the included 'Silica Picture Frame' so that there is no resize, no color changer, no exit button, no name display etc. Over the past three days I have edited the scripts so that I get no errors in my widget and in fact in works perfectly except I want to add the ability to simply click on the current image to apply it as my desktop.

I have downloaded and looked at [extensively] a couple of wallchangers that do work, but require the drag and drop of files, or making of a list to be read etc. They are just a bit too complex for what I want to do though, or just too flashy as a widget. I like the fact that the Silica viewer can read a dir and simply display the images in sequence. I've also spent some time modifying it to look the way I want it to, so that time invested is kind of important to me ... I just need that one added function to make it perfect.

So, what I'd like to know is, how can I add an onLbuttondown [or right] to the silica script? [either one in the widget] Or, isn't it that simple? The reason I ask with regard to the Silica widget is because it came with DX and I figure anyone who is willing to help would already have that as reference.
1,695 views 8 replies
Reply #1 Top
You can use the System.SetWallpaper method. (DX documentation: https://www.stardock.com/products/desktopx/documentation/scripting/system_namespace.html , System namespace docs: https://www.stardock.com/products/desktopx/documentation/scripting/system_namespace.html)

If you know how to obtain the path for the image that's clicked from the script you allready have it's quite straith forward to apply the wallpaper.


Function Object_OnLButtonUp(x, y, dragged)
If Not dragged Then
System.SetWallpaper "C:\temp\wall1.bmp", 1
End If
End Function


For your script, replace the path in the example script (marked bold) with the variable containing the path of the image you want to set as a wallpaper. This example centers it on the desktop. See the docs for how to tile or stretch it.

Hope this helps.
Reply #2 Top
Note, I used the OnLButtonUp function instead of OnLButtonDown as most commands execute when the user releases the mousebutton.
Reply #3 Top
"If you know how to obtain the path..." THAT was what was killing me.
I thought I had to put a path similar to the reference material into the script, but since the widget does all the image loading and displaying via a script I couldn't just put a simple [fixed] path in there.

Eventually I found out that putting "System.SetWallpaper Object.Picture, 1" into the equation worked perfectly, since the script does the full path and image stuff dynamically.

So, thank you thomassen for triggering that key concept into my brain.
Reply #4 Top
Ok, so now I got it to do what I want, sort of. Basically it DOES it fine, but I'm wondering how to do it differently.

When I click on the image it takes any image that is not a BMP and makes a new image with the same prefix, but adds the BMP extension in the folder that the original is in. Also, when I close the widget, it resets my desktop wallpaper back to what it was before I ran the widget.

What I would like to do [I think] is have a temp folder for the bmp files where when I click on the image in the widget, it writes a tmp.bmp to that tmp folder. If I click on a different image in the sequence, it will simply overwrite the other bmp file [so I don't have a bunch of bmp files written to my wallpaper folders]. If possible, I would like the wallpaper set so that when I exit the widget, the last image I clicked on to set as a wall will stay as my desktop wall. I think that has something to do with a registry key. And, when the widget closes, have the temp file cleared from the tmp folder.

I SORT of get the fso and reading a reg entry ... but alas, I have no idea how to combine these things into a working syntax that will not give me errors.

Any help is greatly appreciated.
Reply #5 Top
Hm... for the wallpaper to be persistent I think you have to workaround DX's builtin function. Not sure if all that's needed is to set the registerkey, you might have to send some sort of notification to the system. Can't remember at the moment.

Do you have the current state of your widget availible somewhere? I think at this stage it might be easier to see the code.
Reply #6 Top
Currently I would not feel comfortable sending the widget to anyone yet as it uses a design concept by another artist and I am still trying to get in touch with him for permission.

BUT, I did use the "Silica Picture Frame" widget as the starting point and building block for this widget. In fact, the scripts are almost identical, even down to the naming of the images etc. The only thing I added was:

Function Object_OnLButtonUp(x, y, dragged)
If Not dragged Then
System.SetWallpaper Object.Picture, 1
End If
End Function

...at the bottom of the SDGlass_Frame_Image script.
I removed things like the resizing of the frame and image because this widget needs to be static, and a couple buttons. But as far as I can tell, I didn't remove or change anything that would relate to this wallpaper function or application in any way.
Reply #7 Top
Ok. I'll see if I can have a look at the filenaming thingy later on when I got time. I'm working quite alot this summer though so please bear with me.
Reply #8 Top
I appreciate it .. and believe me when I say, I can wait, no hurry, take your time!