' cd2cmdline.vbs - inserts CD command at the beginning of the Total Commander command line
' v. 04052017
' Replaces clipboard content without restoring
' Requires Internet Explorer and its option "Allow Programmatic clipboard access"
' for "Scripting" set to either "Enable" or "Prompt".
' (if set to "Disable", the script will try to change it to "Prompt" only for its run time and then restore to previous state)
' Written in 2017 by DrShark
' To the extent possible under law, the author(s) have dedicated all copyright and related
' and neighboring rights to this software to the public domain worldwide.
' This software is distributed without any warranty.
' A copy of the CC0 Public Domain Dedication for this software is available at
' <http://creativecommons.org/publicdomain/zero/1.0/>.
Public WSH, objHTML
Set WSH = CreateObject("WScript.Shell")
Set objHTML = CreateObject("htmlfile")
clpaccesskeylocation = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\1407"
On Error Resume Next
clpacckessvalue = WSH.RegRead(clpaccesskeylocation)
If clpacckessvalue > 1 Or Err.Number <> 0 Then WSH.RegWrite clpaccesskeylocation, 1, "REG_DWORD"
main
Sub main
Set clpbrdtext = Nothing
' Inserting CD command to TC cmdline:
WSH.SendKeys "+{Right}{Home}CD "
' Selecting the CD command in the cmdline:
WSH.SendKeys "{Home}"
WSH.SendKeys "{Right}{Right}"
WSH.SendKeys "+{Home}"
' Copy the selected command to clipboard
WSH.SendKeys "^C"
WScript.Sleep 10
clpbrdtext = objHTML.ParentWindow.ClipboardData.GetData("text")
' Check whether command was copied with English keyboard layout:
compstr = StrComp(clpbrdtext, "CD")
If compstr = 0 Then
WSH.SendKeys "{Home}"
quitscript
Else
keyblayoutchange
End If
End Sub
Sub keyblayoutchange
togglevalue = WSH.RegRead("HKCU\Keyboard Layout\Toggle\Hotkey")
Select Case togglevalue
Case 1 togglehotkey = "%+" : Case 2 togglehotkey = "^+" : Case 4 togglehotkey = "`"
End Select
WSH.SendKeys togglehotkey
WSH.SendKeys "{Home}{Right}{Right}{Right}"
WSH.SendKeys "+{Home}"
WSH.SendKeys "{BACKSPACE}"
main
End Sub
Sub quitscript
If clpacckessvalue > 1 Then WSH.RegWrite clpaccesskeylocation, clpacckessvalue, "REG_DWORD"
WScript.Sleep 100
Set clpbrdtext = Nothing
Set objHTML = Nothing
Set WSH = Nothing
End Sub |