Article directory
- 1. Introduction
- 2. Relevant basis
-
- 1. kdeconnect-cli command
- 2. Send to option in the right-click menu of the file
- 3. Hide the command line window when running with vbs
- 3. Write VBS scripts
- 4. Hide format extension and modify icon
1. Introduction
KDE Connect is a cross-platform interconnection open source tool for Linux, Windows, MacOS, Android, and iOS under the famous Linux desktop environment KDE. wait. Its official website address is as follows: https://kdeconnect.kde.org/
Regarding sending files, KDE Connect can send files very conveniently under the KDE desktop environment, because it has added the option of sending to the device to the right-click menu.
However, under Windows, KDE Connect does not register related services in the right-click menu of the file. To send a file, you need to manually click the tray icon, select the device, click to send the file, then select the file, and click to send, which is relatively cumbersome.
This article proposes a method for writing VBS scripts. Use the kdeconnect-cli command to add the KDE Connect device to the right-click Send to option menu, which can quickly send files to the specified device.
2. Relevant basis
1. kdeconnect-cli command
kdeconnect-cli is an executable file called kdeconnect-cli
located in /KDE Connect installation path/bin/
(the default path under Windows is: C: \Program Files\KDE Connect\bin\kdeconnect-cli.exe
), which provides the command line version of some functions of KDE Connect, which can be used for quick operations. Detailed documentation: https://userbase.kde.org/KDE_Connect/Tutorials/Useful_commands
Open the command line, jump to the path where kdeconnect-cli
is located, execute kdeconnect-cli.exe –help to view the help document, as shown in the figure below, you can clearly know the usage of the kdeconnect-cli command.
In the detailed document description, a command (Linux Shell) to send screenshots is given, as follows
file=/tmp/$(hostname)_$(date " + %Y%m%d_%H%M%S").png; spectacle -bo "${file}" & amp; & amp; while ! [ -f "${file}" ]; do sleep 0.5; done & amp; & amp; kdeconnect-cli -d $(kdeconnect-cli -a --id-only) --share "${file}"
The first command defines the file path for storing screenshots. spectacle
is the command to take screenshots. The following while loop is to ensure the success of screenshots. Finally, kdeconnect-cli -d $(kdeconnect- The cli -a --id-only) --share "${file}"
command uses the kdeconnect-cli command to send files.
We pay attention to the –share parameter. Check the help documentation to know that it sends a file or link to the device. At the same time, the -d command specifies the device ID.
kdeconnect-cli -a --id-only
is the command to get device id
Therefore, in order to use kdeconnect-cli to send files, first use kdeconnect-cli -a
to list all devices, get the id of the device (the device ID will generally not change), and then use kdeconnect-cli -d $device ID --share "$file path"
command to send files.
2. Send to option in the right-click menu of the file
There is an option called Send to
in the pop-up menu of the right-click file, and the following default functions are generally available under its submenu.
The list items in this submenu actually correspond to the files in a folder. Enter shell:sendTo
in Run
to quickly open the folder.
Therefore, as long as the files are created under this folder, they will be displayed in Send to
in the file right-click menu.
When you click on the subitem in Send to, the path of the file to be sent will be sent as the only parameter to the file corresponding to the subitem, and the file will then process it.
Write the following bat script under the shell:sendTo
folder for verification (this script only prints the first parameter)
@echo off echo %1 pause
Click Send to, select the newly created test parameter.bat
, you can see the running result, it has printed out the first parameter (that is, the file path).
Therefore, we can write scripts under the shell:sendTo
folder, and use the first parameter to obtain the file path, so as to complete the operation we want on the file.
3. Hide the command line window when running with vbs
Write the following vbs script, which can not display the command line window when running the cmd command (ws.run is the method of executing the command, command is the command to be executed, and the vbhide parameter is to hide the running window)
Set ws = CreateObject("Wscript.Shell") ws.run command, vbhide
WScript.Arguments
can get the parameters passed to the vbs script,WScript.Arguments(0)
can get the first parameter,WScript.Arguments.Count
is the total number of parameters.
3. Write VBS script
To sum up, we can write vbs scripts in the shell:sendTo
folder, and execute the kdeconnect-cli command to complete adding KDE Connect devices in the send to menu, and conveniently send files to in the device. The script is as follows:
' When using send to , there is only one parameter If WScript. Arguments. Count = 1 Then ' The parameter is the path of the file, and use quotation marks (need to be escaped as chr(34)) to enclose it (the path may contain spaces) path = chr(34) & WScript. Arguments(0) &chr(34) ' This parameter is the path of kdeconnect-cli, and use quotation marks (need to be escaped as chr(34)) to enclose it (the path may contain spaces) command_path = chr(34) & amp; "C:\Program Files\KDE Connect\bin\kdeconnect-cli.exe" & amp; chr(34) ' The parameter is deviceID (fill in by yourself) deviceId = "" ' splicing command command = command_path & amp;" -d " & amp;deviceId & amp;" --share " & amp;path \t ' print command when debugging ' MsgBox command \t ' Execute the command and hide the cmd window Set ws = CreateObject("Wscript. Shell") ws.run command, vbhide End If
- In the script, the total number of parameters is judged first, and the total number is guaranteed to be 1.
- Then enclose the first parameter with escaped quotation marks and define it as the
path
variable (the path of the file to be sent), because the file path may contain illegal characters (such as spaces), Enclosing the quotes guarantees that the command will work correctly. - Then define the
command_path
variable to record the path of the kdeconnect-cli command (you also need to use quotation marks). - Define the
deviceId
variable, which is the ID of the device to send the file to, and can be obtained through thekdeconnect-cli -a
command. The ID of the device is generally fixed and can be hardcoded in the script. If there are multiple devices, you can create multiple vbs and only modify thedeviceId
variable - Then splice the commands to form a complete command to send files to the specified device
kdeconnect-cli -d $device ID --share "$file path"
- Finally, execute the command by hiding the cmd command line window.
4. Hide format extension and modify icon
If you directly write the vbs script in the shell:sendTo
folder, the .vbs format extension will be displayed in the option of sendTo
. We can write vbs scripts in other paths, and finally create a shortcut (at the same time, the shortcut can customize the icon), and move it to the shell:sendTo
folder.
The final effect is as follows: