AutoHotkey Community

It is currently May 27th, 2012, 10:44 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Filename argument
PostPosted: February 15th, 2008, 8:40 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2008, 8:59 pm 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2008, 10:25 pm 
ManaUser wrote:
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 16th, 2008, 12:27 am 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8667
Location: Salem, MA
sending {^c} is not the same thing as sending ^c.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 16th, 2008, 3:01 am 
engunneer wrote:
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 16th, 2008, 3:18 am 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
Sorry, usually you can get away without doing this if it's just text, but here's the more correct way:
Code:
#k::
Clipboard =
sendinput ^c
ClipWait
msgbox clipboard=%clipboard%
return


Or if you prefer, you're welcome to use my GetText function from this script.

Code:
#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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 16th, 2008, 4:25 am 
Thanks for your help.. Problem solved. (On my notebook, though, ClipWait 0.1 was insufficient.)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 16th, 2008, 5:10 am 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
Thanks for the feedback. I may need to make that longer then.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2009, 2:15 pm 
Offline

Joined: December 21st, 2007, 9:33 am
Posts: 10
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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, chaosad, specter333, Yahoo [Bot] and 57 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group