My AutoIt script worked as long as I used it via command line. There I could use $CmdLine[1] and pass a path as argument. Now I try to convert the script to a new method to avoid command line arguments.
You open an Explorer Window and select a file e.g C:\test.txt. After that you trigger the AutoIt function with CTRL+WIN+C. The script should look what file is selected in the active Explorer Window and retrieve the path C:\test.txt and assign it to $file variable.
This is my work-in-progress where I'm stuck.
Line 5 $CmdLine[1] needs to be changed to a secret function I don't know.
;Assign key combination "CTRL-WIN-C" to function "copyUNC"
HotKeySet("^#c", "CopyUNC")
;function to copy UNC path of selected Windows Explorer file/folder to clipboard
func CopyUNC()
$file = FileGetLongName($CmdLine[1]) ;THIS LINE NEEDS TO BE CHANGED
$drive = StringLeft($file, 2)
$UNCdrive = DriveMapGet($drive)
If $UNCdrive = "" Then
$UNCfile = $file
else
$UNCfile = $UNCdrive & StringTrimLeft($file, 2)
endif
ClipPut($UNCfile)
endfunc
;necessary loop so AutoIt script stays active and in Tray
While 1
Sleep(100)
WEnd
Q: How do I get the path of a selected file/folder from Windows Explorer into AutoIt v3.3.8.1?
Note #1: I don't want to use registry and right-click tricks to pass the argument
Note #2: If multiple files are selected just pass the first file. Don't overcomplicate things
CMDLINE[1] has nothing to do with what you want.
If you want to activate your script by hotkey AFTER manually selecting the file in Windows Explorer, you need to examine the Explorer window itself.
Here is the function to retrieve selected item in explorer
Func GetExplorerSelection()
Local $saveClip = ""
Local $filesFolders = ""
Local $handle = _WinAPI_GetForegroundWindow()
Local $className = _WinAPI_GetClassName($handle)
If $className = "ExploreWClass" Or $className = "CabinetWClass" Then
$saveClip = ClipGet()
Send("^c")
Sleep(50) ; give clipboard time to react
$filesFolders = ClipGet()
ClipPut($saveClip)
; test if $filesFolders contains #LF and split if so etc..
; code to call StringSplit() etc..
EndIf
EndFunc
maybe this
HotKeySet('{F8}','ccc')
Func ccc()
$ObjWindows = ObjCreate("Shell.Application").Windows()
For $i = 0 To $ObjWindows.Count -1
Local $w = $ObjWindows.Item($i)
Local $aSeLected = $w.Document.SelectedItems()
For $b = 0 To $aSeLected.Count -1
$x = $aSeLected.Item($b)
MsgBox(0,'',$x.Path&'_______'&$x.Name)
Next
Next
EndFunc
While 1
Sleep(100)
WEnd
Related
I'm using the logging facilities, as described in this other post:
OUTPUT TO VALUE("C:\Temp_Folder\logfile.txt").
...
PUT UNFORMATTED "Start : Check-zones" SKIP.
...
OUTPUT CLOSE.
This is working fine.
Now I would like to add the results of an OS-COMMAND in the output file.
I've already tried the following: (putting the results in a newly to be created file)
OS-COMMAND NO-WAIT VALUE("WMIC printer get name, deviceID >> C:\Temp_Folder\Printers.txt").
This is working fine.
So, I know the command is working fine. However, the following is not working:
OS-COMMAND NO-WAIT VALUE("WMIC printer get name, deviceID >> C:\Temp_Folder\LogFile.txt").
This is obvious, because C:\Temp_Folder\Logfile.txt is locked for writing by the progress application, so the shell, opened by OS-COMMAND can't write to that file.
In order to overcome this, I would like to catch the results of the OS-COMMAND's results.
How can I do this?
Unfortunately back in the dark ages when os-command was designed, it was considered useful to suppress all errors.
You can either start a batch file and let that do some “guaranteed” output error handling, see https://knowledgebase.progress.com/articles/Article/21039
Or (since you are on Windows) you can use the .Net system diagnostics process class (which you will want to wrap in your own method or function to simplify use):
DEFINE VARIABLE oProcess AS System.Diagnostics.Process NO-UNDO.
DEFINE VARIABLE lcstderr AS LONGCHAR NO-UNDO.
DEFINE VARIABLE lcstdout AS LONGCHAR NO-UNDO.
oProcess = NEW System.Diagnostics.Process().
oProcess:StartInfo:FileName = "wmic.exe".
oProcess:StartInfo:Arguments = "printer get name, deviceID".
oProcess:StartInfo:CreateNoWindow = TRUE.
oProcess:StartInfo:UseShellExecute = FALSE.
oProcess:StartInfo:RedirectStandardError = TRUE.
oProcess:StartInfo:RedirectStandardOutput = TRUE.
oProcess:Start().
lcstdout = oProcess:StandardOutput:ReadToEnd().
lcstderr = oProcess:StandardError:ReadToEnd().
oProcess:WaitForExit().
lcstdout = lcstdout + oProcess:StandardOutput:ReadToEnd().
lcstderr = lcstderr + oProcess:StandardError:ReadToEnd().
I'm trying to get Autokey to work like Autohotkey worked for me in Windows.
One very useful function that was possible to set up in Autohotkey was assigning a keyboard key to grab highlighted text, then go to url, grab that url, and then insert the highlighted text and URL in specific places within a predetermined phrase.
It was extremely useful to create text with links in different formats.
The Autohotkey script for what I'm describing looked something like this:
insert::
clipboard =
Send, ^c
ClipWait
myText = %clipboard%
Send, !d
clipboard =
Send, ^c
ClipWait
myURL = %clipboard%
myLink = %myText%
clipboard = %myLink%
return
Is there a way to translate that into a working Autokey script?
# assigning a keyboard key to
# `hotkey - a key or combination of keys that, when pressed, will trigger AutoKey to do something; run a script, insert a phrase or display a menu. A hotkey can be created using any key on the keyboard (within reason), with or without one or more modifier keys. The modifier keys are Shift, Control, Alt and Super (a.k.a. Windows).`
# [Guide](https://github.com/autokey/autokey/wiki/Beginners-Guide)
import os, time
# grab highlighted text
myText = clipboard.get_selection()
# then go to url
myCmd = "/usr/bin/firefox --new-window http://www. your site .biz/"
os.system(myCmd)
time.sleep(0.25)
# grab that url, and then
keyboard.send_keys('<F6>')
time.sleep(0.25)
myURL = clipboard.get_selection()
# insert the highlighted text and URL in specific places within a predetermined phrase.
# run a window wait, then paste the texts there. Following example opens a msgbox2sec.ahk (create it first):
myCmd = 'wine ~/.wine/drive_c/Program\ Files/AutoHotkey/AutoHotkey.exe /home/administrator/Desktop/msgbox2sec.ahk'
os.system(myCmd)
time.sleep(0.25)
active_class = window.get_active_class()
if not active_class == "your class name": # for example: "autokey-gtk.Autokey-gtk":
time.sleep(0.25) # sleep longer
myLink = "" + myText + ""
# paste your link, then copy it:
keyboard.send_keys(myLink)
# select select a line:
keyboard.send_keys('<home>')
keyboard.send_keys("<shift>+<end>")
# copy line to clipboard:
keyboard.send_keys('<ctrl>+c')
# or copy line to variable:
c = clipboard.get_selection()
I want to set the filters on an existing .xls-file by running a shell script from the command line.
powershell -c "$excelObj = New-Object -ComObject Excel.Application;$excelWorkBook = $excelObj.Workbooks.Open(\"C:\Users\Desktop\Papierkorb\Test\test2.xlsx\");$excelWorkSheet = $excelObj.WorkSheets.item(\"Sheet1\");$excelWorkSheet.activate();$headerRange = $excelWorkSheet.Range(\"A1\",\"A1\").AutoFilter() | Out-Null;$excelWorkBook.Save();$excelWorkBook.Close();$excelObj.Quit()"
I am getting an error message:
Unable to get the AutoFilter property of the Range class
At line:1 char:231
I tried several adaptions with the Range, but could not fix it.
Thanks for your help,
It is not possible to set AutoFilter on a range without data.
Try to put some text into cell "A1" in the test2.xlsx file (either using Excel, or problematically with PowerShell, example below). You can even put empty string ''.
The following works for me.
$excelObj = New-Object -ComObject Excel.Application;$excelWorkBook = $excelObj.Workbooks.Open("d:\temp\test2.xlsx");
$excelWorkSheet = $excelObj.WorkSheets.item("Sheet1");
$excelWorkSheet.activate();
$headerRange = $excelWorkSheet.Range("A5","A5") ;
$headerRange.Item(1,1) = 'Something'
$headerRange.AutoFilter() ;
#$headerRange.AutoFilter() | Out-Null;
$excelWorkBook.Save();
$excelWorkBook.Close();
$excelObj.Quit()
I use an automation script that tests a browser-based application. I'd like to save the visible text of each page I load as a text file. This needs to work for the current open browser window. I've come across some solutions that use InternetExplorer.Application but this won't work for me as it has to be the current open page.
Ideally, I'd like to achieve this using vbscript.
Any ideas how to do this?
You can attach to an already running IE instance like this:
Set app = CreateObject("Shell.Application")
For Each window In app.Windows()
If InStr(1, window.FullName, "iexplore", vbTextCompare) > 0 Then
Set ie = window
Exit For
End If
Next
Then save the document body text like this:
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("output.txt", 2, True)
f.Write ie.document.body.innerText
f.Close
If the page contains non-ASCII characters you may need to create the output file with Unicode encoding:
Set f = fso.OpenTextFile("output.txt", 2, True, -1)
or save it as UTF-8:
Set stream = CreateObject("ADODB.Stream")
stream.Open
stream.Type = 2 'text
stream.Position = 0
stream.Charset = "utf-8"
stream.WriteText ie.document.body.innerText
stream.SaveToFile "output.txt", 2
stream.Close
Edit: Something like this may help getting rid of script code in the document body:
Set re = New RegExp
re.Pattern = "<script[\s\S]*?</script>"
re.IgnoreCase = True
re.Global = True
ie.document.body.innerHtml = re.Replace(ie.document.body.innerHtml, "")
WScript.Echo ie.document.body.innerText
I am currently using the following code to select a file and add its path to a text box.
Dim objDialog As Object
Set objDialog = Application.FileDialog(3)
With objDialog
.AllowMultiSelect = False
.Show
If .SelectedItems.Count = 0 Then
MsgBox "No file selected."
Else
Me.FileNameTextBox = Dir(.SelectedItems(1))
End If
End With
Set objDialog = Nothing
How do I make it so the entire file path is inserted, not just the file name?
.SelectedItems(n) already contains the full path and filename. If what you need is just to separate the name of the file from its path, instead of using the Dir function you could use something like this:
Me.FileNameTextBox = Mid$(.SelectedItems(1), InStrRev(.SelectedItems(1), "\") + 1)
Me.PathTextBox = Left$(.SelectedItems(1), InStrRev(.SelectedItems(1), "\"))
Hope this helps!
you need to remove the dir() part, EG....
Me.FileNameTextBox = .SelectedItems(1)