Creating Shortcuts via Scripting
Beginner
from
JoeUser Forums
CREATING SHORTCUTS- via scripting
Beginner
Creating shortcuts in DX is easy. Just create an object and open its properties. In the ‘General’ tab next to ‘Object Type’ click ‘change’. In the drop-down, select shortcut.
Now you see you can make it a file shortcut or a folder shortcut. You can choose from the presets in the drop-downs or browse. You also have the option of opening a folder shortcut as a popup menu. DX even allows you to customize where the menu pops up and how it opens out. Yes sir, that was mighty easy!
Now let’s say for whatever reason you might need the ability to change the target of an object when it’s in widget mode (which you can’t do if you set the shortcut in object properties). It might be anything from a URL, to a location of a file on your computer. Of course the user could always load up DesktopX Builder and make the necessary changes there but it never hurts to have that extra ease of use and configurability.
We’re going to make a shortcut by script, and in my opinion it’s just as easy as making one through object properties. There are many ways to do this and here I’ll show you 2.
The first way is to use the simple drag and drop method known as Sub Object_OnDropFiles. Link- DevGuide Object Callbacks(scroll down)
STEP 1- Creating an object
Right click on the Desktopx Builder icon and choose ‘New Object’. On to step two! (I told you this was easy.)
STEP 2- Setting the target
By using OnDropFiles we’ll get the full path to the file (or folder)
We’ll use the shell object to actually perform the task of opening up the target in a window on Left click.
Insert the script below:
Dim FilePath
Sub Object_OnDropFiles(files)
'If a number of files are selected, choose the first one
getonefile= Split(files, "|")
getfirstfile = LBound(getonefile)
FilePath = getonefile(getfirstfile)
Msgbox files
Msgbox FilePath
End Sub
'--Go to selected target on L-click
Sub Object_OnLbuttonUp(x,y,dragged)
If Not dragged Then
On Error Resume Next
Set Sh = CreateObject("WScript.Shell")
Sh.Run (Chr(34)& FilePath & Chr(34))
Set Sh = Nothing
End If
End Sub
You might notice I inserted 2 message boxes into the OnDropFiles function. These will pop up when you drop files onto the object. The first message box to appear will list the group of files you dropped onto the object, and the 2nd will show the first file in that group. The file in the 2nd message box is your target.
Now open up a window to your Documents. Select a couple of files and drag & drop them onto the object. Click on the object and voila! You have a shortcut that’s a cinch to configure.
The second method I’ll be demonstrating uses another function you can find in the Developer’s guide: System.FolderDialog. Link- DevGuide System Namespace(scroll down)
STEP 1- create another object.
STEP 2- Setting the target
We’ll still be using the shell object to open up the target in a window on Left click.
This time, we’ll use System.FolderDialog to navigate to the file or folder you want on Right click.
Dim FilePath
'--Go to selected target on L-click
Sub Object_OnLbuttonUp(x,y,dragged)
If Not dragged Then
On Error Resume Next
Set Sh = CreateObject("WScript.Shell")
Sh.Run (Chr(34)& FilePath & Chr(34))
Set Sh = Nothing
End If
End Sub
'--Open folders dialog on R-click
Function Object_OnRButtonUpEx(obj,x,y,dragged)
If Not dragged Then
Object_OnRButtonUpEx = True
Opendialog
End If
End Function
'--Function to open folders dialog
Sub Opendialog
selectedfile = System.FolderDialog("", "", &H4000)'--Browse for all folders
If selectedfile <> "" Then '--Only set target if user selects something
FilePath = selectedfile
End If
End Sub
Now, right-click on the object and browse for a file, folder, or program. Left-click and you’re off!
I often see someone asking how to get a shortcut to My Computer because the listing in object properties doesn’t work. The second method here will do that.
Just in case you want to know how to code an object to open My Computer without navigating, insert the code below.
Sub Object_OnLbuttonUp(x,y,dragged)
If Not dragged Then
On Error Resume Next
Set Sh = CreateObject("WScript.Shell")
Sh.Run (Chr(34)& “” & Chr(34))
Set Sh = Nothing
End If
End Sub
As you can see I left the file path empty “” so DX opens My Computer by default.
That’s it! Thanks for reading.
P.S: DesktopX Wiki - Shortcuts: Link
Beginner
Creating shortcuts in DX is easy. Just create an object and open its properties. In the ‘General’ tab next to ‘Object Type’ click ‘change’. In the drop-down, select shortcut.
Now you see you can make it a file shortcut or a folder shortcut. You can choose from the presets in the drop-downs or browse. You also have the option of opening a folder shortcut as a popup menu. DX even allows you to customize where the menu pops up and how it opens out. Yes sir, that was mighty easy!
Now let’s say for whatever reason you might need the ability to change the target of an object when it’s in widget mode (which you can’t do if you set the shortcut in object properties). It might be anything from a URL, to a location of a file on your computer. Of course the user could always load up DesktopX Builder and make the necessary changes there but it never hurts to have that extra ease of use and configurability.
We’re going to make a shortcut by script, and in my opinion it’s just as easy as making one through object properties. There are many ways to do this and here I’ll show you 2.
The first way is to use the simple drag and drop method known as Sub Object_OnDropFiles. Link- DevGuide Object Callbacks(scroll down)
STEP 1- Creating an object
Right click on the Desktopx Builder icon and choose ‘New Object’. On to step two! (I told you this was easy.)
STEP 2- Setting the target
By using OnDropFiles we’ll get the full path to the file (or folder)
We’ll use the shell object to actually perform the task of opening up the target in a window on Left click.
Insert the script below:
Dim FilePath
Sub Object_OnDropFiles(files)
'If a number of files are selected, choose the first one
getonefile= Split(files, "|")
getfirstfile = LBound(getonefile)
FilePath = getonefile(getfirstfile)
Msgbox files
Msgbox FilePath
End Sub
'--Go to selected target on L-click
Sub Object_OnLbuttonUp(x,y,dragged)
If Not dragged Then
On Error Resume Next
Set Sh = CreateObject("WScript.Shell")
Sh.Run (Chr(34)& FilePath & Chr(34))
Set Sh = Nothing
End If
End Sub
You might notice I inserted 2 message boxes into the OnDropFiles function. These will pop up when you drop files onto the object. The first message box to appear will list the group of files you dropped onto the object, and the 2nd will show the first file in that group. The file in the 2nd message box is your target.
Now open up a window to your Documents. Select a couple of files and drag & drop them onto the object. Click on the object and voila! You have a shortcut that’s a cinch to configure.
The second method I’ll be demonstrating uses another function you can find in the Developer’s guide: System.FolderDialog. Link- DevGuide System Namespace(scroll down)
STEP 1- create another object.
STEP 2- Setting the target
We’ll still be using the shell object to open up the target in a window on Left click.
This time, we’ll use System.FolderDialog to navigate to the file or folder you want on Right click.
Dim FilePath
'--Go to selected target on L-click
Sub Object_OnLbuttonUp(x,y,dragged)
If Not dragged Then
On Error Resume Next
Set Sh = CreateObject("WScript.Shell")
Sh.Run (Chr(34)& FilePath & Chr(34))
Set Sh = Nothing
End If
End Sub
'--Open folders dialog on R-click
Function Object_OnRButtonUpEx(obj,x,y,dragged)
If Not dragged Then
Object_OnRButtonUpEx = True
Opendialog
End If
End Function
'--Function to open folders dialog
Sub Opendialog
selectedfile = System.FolderDialog("", "", &H4000)'--Browse for all folders
If selectedfile <> "" Then '--Only set target if user selects something
FilePath = selectedfile
End If
End Sub
Now, right-click on the object and browse for a file, folder, or program. Left-click and you’re off!
I often see someone asking how to get a shortcut to My Computer because the listing in object properties doesn’t work. The second method here will do that.
Just in case you want to know how to code an object to open My Computer without navigating, insert the code below.
Sub Object_OnLbuttonUp(x,y,dragged)
If Not dragged Then
On Error Resume Next
Set Sh = CreateObject("WScript.Shell")
Sh.Run (Chr(34)& “” & Chr(34))
Set Sh = Nothing
End If
End Sub
As you can see I left the file path empty “” so DX opens My Computer by default.
That’s it! Thanks for reading.
P.S: DesktopX Wiki - Shortcuts: Link