Apologies for such elementary question:
In the windows explorer a single file is marked. How can a script access the filename (with or without complete path)?
Oskar
Filename argument
Started by
Guest
, Feb 15 2008 07:40 PM
8 replies to this topic
#1
-
Posted 15 February 2008 - 07:40 PM
One way is to send ^c (meaning copy) and then get the path from the clipboard. Would that work?
You can back up and later restore the previous content of the clipboard if you don't want to lose it.
You can back up and later restore the previous content of the clipboard if you don't want to lose it.
#2
-
Posted 15 February 2008 - 07:59 PM
I guess it should but I can't get it to work. Anything wrong withOne way is to send ^c (meaning copy) and then get the path from the clipboard. Would that work?
----
#k::
sendinput {^c}
msgbox clipboard=%clipboard%
return
----
The clipboard is unaffected by the macro.
Oskar
#3
-
Posted 15 February 2008 - 09:25 PM
sending {^c} is not the same thing as sending ^c.
#4
-
Posted 15 February 2008 - 11:27 PM
Thanks. Couldn't find the difference in the help file. There still remains a timing problem (apparently):sending {^c} is not the same thing as sending ^c.
#k::
sendinput ^c
msgbox clipboard=%clipboard%
msgbox clipboard=%clipboard%
return
The first msgbox reports the previous content. Only the second reports the actual result of the ^c copy-operation.
#5
-
Posted 16 February 2008 - 02:01 AM
Sorry, usually you can get away without doing this if it's just text, but here's the more correct way:
Or if you prefer, you're welcome to use my GetText function from this script.
#k:: [color=red]Clipboard =[/color] sendinput ^c [color=red]ClipWait[/color] msgbox clipboard=%clipboard% return
Or if you prefer, you're welcome to use my GetText function from this script.
#k:: GetText(FileName) msgbox clipboard=%FileName% return GetText(ByRef MyText = "") { SavedClip := ClipboardAll Clipboard = Send ^c ClipWait 0.1 If ERRORLEVEL { Clipboard := SavedClip MyText = ERRORLEVEL := 1 Return } MyText := Clipboard Clipboard := SavedClip Return MyText }That has the extra feature of preserving the previous clipboard contents.
#6
-
Posted 16 February 2008 - 02:18 AM
Thanks for your help.. Problem solved. (On my notebook, though, ClipWait 0.1 was insufficient.)
#7
-
Posted 16 February 2008 - 03:25 AM
Thanks for the feedback. I may need to make that longer then.
#8
-
Posted 16 February 2008 - 04:10 AM
As a datapoint, I had to set the delay value to 2... I don't understand why it's so slow on my machine. Interestingly enough, when this script is run over windows shortcuts (lnk files), the message box pops up almost instantly, but otherwise it has a perceptible delay.
#9
-
Posted 05 July 2009 - 01:15 PM