Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Filename argument


  • Please log in to reply
8 replies to this topic
  • Guests
  • Last active:
  • Joined: --
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

ManaUser
  • Members
  • 1121 posts
  • Last active: Dec 07 2016 04:24 PM
  • Joined: 24 May 2007
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.

  • Guests
  • Last active:
  • Joined: --

One way is to send ^c (meaning copy) and then get the path from the clipboard. Would that work?

I guess it should but I can't get it to work. Anything wrong with
----
#k::
sendinput {^c}
msgbox clipboard=%clipboard%
return
----
The clipboard is unaffected by the macro.

Oskar

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
sending {^c} is not the same thing as sending ^c.

  • Guests
  • Last active:
  • Joined: --

sending {^c} is not the same thing as sending ^c.

Thanks. Couldn't find the difference in the help file. There still remains a timing problem (apparently):
#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.

ManaUser
  • Members
  • 1121 posts
  • Last active: Dec 07 2016 04:24 PM
  • Joined: 24 May 2007
Sorry, usually you can get away without doing this if it's just text, but here's the more correct way:
#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.

  • Guests
  • Last active:
  • Joined: --
Thanks for your help.. Problem solved. (On my notebook, though, ClipWait 0.1 was insufficient.)

ManaUser
  • Members
  • 1121 posts
  • Last active: Dec 07 2016 04:24 PM
  • Joined: 24 May 2007
Thanks for the feedback. I may need to make that longer then.

dnquark
  • Members
  • 10 posts
  • Last active: Jan 03 2011 07:39 AM
  • Joined: 21 Dec 2007
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.