Published with waiting for a great help from Zubaz.
Published on October 2, 2007 By Vad_M In DesktopX Tutorials
Note: Sorry but I can’t format or (and) edit this text better than you see below. I’m sure this is one more Wincustomize bug. However I hope that Zubaz will help me to solve this problem…

1. A few words about using DX timers in the multifunctional applications like system meters:

Of course we can use the integrated DesktopX functions to get full system information or to create any other system meters. This is very comfortable options for beginners but there is one problem. You can't manage the timers which uses in the "integrated" scripts. As a result this may brings about the overweening usage of CPU and (or) System Memory.

I have discovered this problem when worked on the first version of System Navigator:
https://www.wincustomize.com/skins.aspx?skinid=669&libid=34. However this little problem has very simple decision. You need only create your own script with the single (main) timer which will manage all of processes and functions in your widget. The using of CPU and Memory will be minimal in this case.

For example you want get the full information about your system configuration, disk drives as well as the network connections and traffic. If you use the DX meters for this and unite all of these meters in the one widget you will see the abnormal CPU usage. So you need create the Main (parent) Script Object with the single timer which will start the auxiliary (children) scripts on the each of these objects if one of them is active (visible) and will stop all other scripts on the inactive (invisible) objects. As you see this is more than easy!

This is just a several lines with a simple theory that may help you to optimize your future scripts. Someday we will have the detailed conversation about scripting for system meters but now I offer to speak about more simple things.

2. The easy way to check the Gmail incoming e-mails:

You need create one text object (desktopx.object("mymails").text) and the Script Object to apply this code:

'****************************************** BEGIN OF THE SCTIPT *******************************************

Dim username, password

Sub Object_OnScriptEnter
username = "YOUR GMAIL USER NAME"
'for example if your address is "mike1992@gmail.com" - the user name is just: "mike1992"
password = "YOUR PASSWORD"
Object.SetTimer 1,(60000*5) '<== this will check your Gmail each 5 minutes
End Sub

Sub Object_OnTimer1000 '<== main timer
Call CheckGmail(username,password,0,"")
End Sub

Sub CheckGmail(un,ps,im,strx)
On Error Resume Next
Dim ac,url,objXML,strmail
If instr(un,"@") > 0 Then ac = split(un,"@")(0)&":"&ps Else ac = un&":"&ps '<== this line is need if you forget to extract your user name from Gmail address
url = "https://"&ac&"@gmail.google.com/gmail/feed/atom"
Set objXML = CreateObject("Microsoft.XMLHTTP")
objXML.Open "GET", url, False
objXML.send "Authentication" '<== First of all you should confirm the authenticity of Gmail user
objXML.Open "GET", url, False
objXML.send "Gmail Information" '<== Hereon you can retrieve the necessary information
strx = objXML.responseText
Set objXML = nothing
If strx <> "" Then
If instr(LCase(strx),"fullcount") > 0 Then im = ParseString(strx,"","")
End If
If int(im) = 1 Then strmail = "mail" Else strmail = "mails"
desktopx.object("mymails").text = im&strmail '<== final results
End Sub

Function ParseString(strx,tag1,tag2) '<== this function will allow you to extract any data from XML string by tags
Dim x1,x2,xlen
x1 = instr(LCase(strx), LCase(tag1))
x2 = instr(LCase(strx), LCase(tag2))
If x1 = 0 Or x2 = 0 Then
Exit Function '<== error of parsing...
Else
xlen = len(tag1)
ParseString = mid(strx, x1 + xlen, x2 - x1 - xlen)
End If
End Function

Sub Object_OnScriptExit
Object.KillTimer 1 '<== Clear all...
Set username = nothing
Set password = nothing
End Sub

'************************************************ END ***************************************************

3. How to get the System Uptime:

Visualize that you work on a system clock that must show you not only the current time but the system uptime too. No doubt you may not use the integrated DX function for this. But if you want that these both values has been timed you must do something like this:

You need create two text objects:
desktopx.object("localtime").text
desktopx.object("worktime").text
and one main Script Object where you will put the following code:

'****************************************** BEGIN OF THE SCTIPT *******************************************

Dim uptime

Sub Object_OnScriptEnter
On Error Resume Next
'A lot of useful information we can find just in the Windows registry...
Dim sd,sb
Set objShell = CreateObject("WScript.Shell") '<== get the default format of short date
sd = objShell.RegRead("HKEY_CURRENT_USER\Control Panel\International\sShortDate")
Set objShell = nothing
'Now we know how our short date looks. Let's use WMI to get the walue of last system reboot.
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set objSYS = objWMI.ExecQuery("Select LastBootUpTime from Win32_OperatingSystem")
For Each item In objSYS
sb = item.LastBootUpTime '<== get the value of last system reboot
uptime = StringToDate(sd,sb) '<== formating the date/time value
Exit For
Next
'Clear the memory from unnecessary values
Set objSYS = nothing
Set objWMI = nothing
Set sd = nothing
Set sb = nothing
Object.SetTimer 1000, 1000
End Sub

Sub Object_OnTimer1000 '<== main timer
desktopx.object("localtime").text = FormatDateTime(Time,3) '<== this will show you current time
desktopx.object("worktime").text = GetUptime(uptime,Now)
End Sub

Function StringToDate(,xb)
If left(LCase(),1) = "d" Then '<== what is the first - the mohth or the day?
StringToDate = cdate(mid(xb, 7, 2)&"."& _
mid(xb, 5, 2)&"."&left(xb, 4) _
&" "&mid (xb, 9, 2)&":"&mid(xb, 11, 2)&":"&mid(xb, 13, 2))
Else
StringToDate = cdate(mid(xb, 5, 2)&"/"& _
mid(xb, 7, 2)&"/"&left(xb, 4) _
&" "&mid (xb, 9, 2)&":"&mid(xb, 11, 2)&":"&mid(xb, 13, 2))
End If
'As a result you will get the string like: "27.09.2007 10:56:14" if the day is first or "09/27/2007 10:56:14" in the other case.
End Function

Function GetUptime(t1,t2) '<== refreshing the value of uptime
Dim xt,h,m,s
xt = DateDiff("s",t1,t2) '<== Date different between the uptime and current date/time
h = int(xt/3600) Mod 100 '<== get the hours
m = int(xt/60) Mod 60 '<== get the minutes
s = xt Mod 60 '<== get the seconds
h = AddZero(h)
m = AddZero(m)
s = AddZero(s)
GetUptime = h&":"&m&":"&s
End Function

Function AddZero(val) '<== add zero before the number
If len(val) = 1 Then AddZero = "0"&val Else AddZero = val
End Function

Sub Object_OnScriptExit
Object.KillTimer 1000 '<== Clear all...
Set uptime = nothing
End Sub

'************************************************ END ***************************************************

4. How to get the list of attributes from mp3 files:

Sometimes we need work with media files like audio, video, photo etc... For example when we create new Media Player. What the information we can find in the *.mp3 files and how to get it?

First of all you need create a simple listbox by using DesktopX Listbox ActiveX control to display the results and the Script Object to apply this code:

'****************************************** BEGIN OF THE SCTIPT *******************************************

Sub Object_OnScriptEnter
desktopx.ScriptObject("xbox").control.resetlist
End Sub

Sub Object_OnLButtonUp(x,y,dragged)
If Not dragged Then
On Error Resume Next
Dim xfile,objFSO
xfile = inputbox("Enter the path to *.mp3 file to get its attributes","Input Box")
If xfile = "" Then Exit Sub
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(xfile) Then Call GetFileInfo(xfile)
Set xfile = nothing
Set objFSO = nothing
End If
End Sub

Sub GetFileInfo(xfile)
On Error Resume Next
Dim objFSO,objFIL,fopath,finame,objShell,objFOL,objItem
desktopx.ScriptObject("xbox").control.resetlist
Set objFSO = CreateObject("Scripting.FileSystemObject")
fopath = objFSO.GetParentFolderName(xfile)
Set objFIL = objFSO.GetFile(xfile)
finame = objFIL.name
Set objFIL = nothing
Set objFSO = nothing
Set objShell = CreateObject("Shell.Application")
Set objFOL = objShell.NameSpace(fopath)
Set objItem = objFOL.ParseName(finame)
desktopx.ScriptObject("xbox").control.additem "File Name: "&objFOL.GetDetailsOf(objItem,0)
desktopx.ScriptObject("xbox").control.additem "File Size: "&objFOL.GetDetailsOf(objItem,1)
desktopx.ScriptObject("xbox").control.additem "File Type: "&objFOL.GetDetailsOf(objItem,2)
'desktopx.ScriptObject("xbox").control.additem "Last Modified: "&objFOL.GetDetailsOf(objItem,3)
'desktopx.ScriptObject("xbox").control.additem "Date Created: "&objFOL.GetDetailsOf(objItem,4)
'desktopx.ScriptObject("xbox").control.additem "Date Accessed: "&objFOL.GetDetailsOf(objItem,5)
'desktopx.ScriptObject("xbox").control.additem "Attributes: "&objFOL.GetDetailsOf(objItem,6)
'desktopx.ScriptObject("xbox").control.additem "Status: "&objFOL.GetDetailsOf(objItem,7)
'desktopx.ScriptObject("xbox").control.additem "Owner: "&objFOL.GetDetailsOf(objItem,8)
desktopx.ScriptObject("xbox").control.additem "Author: "&objFOL.GetDetailsOf(objItem,9)
desktopx.ScriptObject("xbox").control.additem "Title: "&objFOL.GetDetailsOf(objItem,10)
'desktopx.ScriptObject("xbox").control.additem "Subject: "&objFOL.GetDetailsOf(objItem,11)
'desktopx.ScriptObject("xbox").control.additem "Category: "&objFOL.GetDetailsOf(objItem,12)
'desktopx.ScriptObject("xbox").control.additem "Pages: "&objFOL.GetDetailsOf(objItem,13)
'desktopx.ScriptObject("xbox").control.additem "Comments: "&objFOL.GetDetailsOf(objItem,14)
'desktopx.ScriptObject("xbox").control.additem "Copyright: "&objFOL.GetDetailsOf(objItem,15)
desktopx.ScriptObject("xbox").control.additem "Artist: "&objFOL.GetDetailsOf(objItem,16)
desktopx.ScriptObject("xbox").control.additem "Album: "&objFOL.GetDetailsOf(objItem,17)
desktopx.ScriptObject("xbox").control.additem "Year: "&objFOL.GetDetailsOf(objItem,18)
desktopx.ScriptObject("xbox").control.additem "Track Number: "&objFOL.GetDetailsOf(objItem,19)
desktopx.ScriptObject("xbox").control.additem "Genre: "&objFOL.GetDetailsOf(objItem,20)
desktopx.ScriptObject("xbox").control.additem "Duration: "&objFOL.GetDetailsOf(objItem,21)
desktopx.ScriptObject("xbox").control.additem "Bit Rate: "&objFOL.GetDetailsOf(objItem,22)
desktopx.ScriptObject("xbox").control.additem "Protected: "&objFOL.GetDetailsOf(objItem,23)
'desktopx.ScriptObject("xbox").control.additem "Camera Model: "&objFOL.GetDetailsOf(objItem,24)
'desktopx.ScriptObject("xbox").control.additem "Date Picture Taken: "&objFOL.GetDetailsOf(objItem,25)
'desktopx.ScriptObject("xbox").control.additem "Dimensions: "&objFOL.GetDetailsOf(objItem,26)
'27,28 and 31 - the "empty" keys
'desktopx.ScriptObject("xbox").control.additem "Episode Name: "&objFOL.GetDetailsOf(objItem,29)
'desktopx.ScriptObject("xbox").control.additem "Program Description: "&objFOL.GetDetailsOf(objItem,30)
desktopx.ScriptObject("xbox").control.additem "Audio Sample Size: "&objFOL.GetDetailsOf(objItem,32)
desktopx.ScriptObject("xbox").control.additem "Audio Sample Rate: "&objFOL.GetDetailsOf(objItem,33)
desktopx.ScriptObject("xbox").control.additem "Audio Channels: "&objFOL.GetDetailsOf(objItem,34)
'desktopx.ScriptObject("xbox").control.additem "Company: "&objFOL.GetDetailsOf(objItem,35)
'desktopx.ScriptObject("xbox").control.additem "Description: "&objFOL.GetDetailsOf(objItem,36)
'desktopx.ScriptObject("xbox").control.additem "File Version: "&objFOL.GetDetailsOf(objItem,37)
'desktopx.ScriptObject("xbox").control.additem "Product Name: "&objFOL.GetDetailsOf(objItem,38)
'desktopx.ScriptObject("xbox").control.additem "Product Version: "&objFOL.GetDetailsOf(objItem,39)
Set objFOL = nothing
Set objItem = nothing
Set objShell = nothing
End Sub

'************************************************ END ***************************************************

5. How to get a list of media files in a folder:

* You need create a simple listbox to display the results and the Script Object to apply this code:

'****************************************** BEGIN OF THE SCTIPT *******************************************

Sub Object_OnScriptEnter
desktopx.ScriptObject("xbox").control.resetlist
End Sub

Sub Object_OnLButtonUp(x,y,dragged)
If Not dragged Then
On Error Resume Next
Dim xfolder,xarray
xfolder = System.FolderDialog ("Select a Music Folder to list its content...","",0)
xarray = ""
If xfolder = "" Then Exit Sub
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(xfolder) Then xarray = OnBrowse_Ex(xfolder,sf)
Set xfolder = nothing
Set objFSO = nothing
If xarray <> "" Then Call ViewResults(xarray)
End If
End Sub

Sub ViewResults(xarray)
desktopx.ScriptObject("xbox").control.resetlist
For Each item In SortArray(xarray,"")
If len(item) > 4 Then
desktopx.ScriptObject("xbox").control.additem "File Name: "&split(item,"|")(0)
desktopx.ScriptObject("xbox").control.additem "File Path: "&split(item,"|")(1)
desktopx.ScriptObject("xbox").control.additem ""
End If
Next
End Sub

Function OnBrowse_Ex(fp,sf) '<== Using the Recursive Algorithm to get a list of all of the files in a folder
On Error Resume Next
Dim objFSO,objFOL,objFIL,EXT,objSUB
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFOL = objFSO.GetFolder(fp)
If objFOL.Files.count > 0 Then
Set objFIL = objFOL.Files
For Each Item In objFIL
EXT = LCase(objFSO.GetExtensionName(Item.path))
'Filtering by file extension
If IsMedia(EXT) Then sf = sf&Item.name&"|"&Item.path&"" '<== the separator
Next
Set objFIL = nothing
End If
Set objSUB = objFOL.SubFolders
If objSUB.count > 0 Then '<== get all subfolders
For Each subItem In objSUB
Call OnBrowse_Ex(subItem.path,sf)
Next
End If
Set EXT = nothing
Set objSUB = nothing
Set objFOL = nothing
Set objFSO = nothing
OnBrowse_Ex = sf
End Function

Function IsMedia(val)
Select Case LCase(val) '<== audio, video, movie, images, metafiles, etc... >
Case "aif","aifc","aiff","asf","asx","au","avi","cda","dvr-ms","ifo","jpeg","jpg","m1v","m3u","m3u8"
IsMedia = True
Case "mid","midi","mp2","mp3","mpa","mpe","mpeg","mpg","ogg","pls","rmi","snd","vob","wav","wax"
IsMedia = True
Case “wm","wma","wmd","wmv",”wmx","wpl","wvx"
IsMedia = True
Case Else
IsMedia = False
End Select
End Function

Function SortArray(xarray,sep) ‘<== THE ALPHABETICAL SORTING
xarray = split(xarray,sep)
For i = 0 To UBound(xarray) - 1
j = i
For k = i To UBound(xarray)
If xarray(j) > xarray(k) Then
j = k
End If
Next
strtemp = xarray(j) '<== bubble sorting
xarray(j) = xarray(i)
xarray(i) = strtemp
Next
SortArray = xarray
End Function

'************************************************ END ***************************************************

This is all for now. Please let me know what the code examples you want see at the next time.

Comments
on Oct 02, 2007
If you email . . i can try to format for you.
on Oct 02, 2007
Thank you! I'll try once again and send it for you if the results will be negative.

This is very strange Wincustomize bug. May be I see it because I use Maxton 2.0? Now I open my IE7.

I already uploaded this article to the Wincustomize.Wiki. But I think that it would be great if this article will be here in the DesktopX tutorials.

Thank you again!

Best Regards,
Vadim.