topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Sunday December 15, 2024, 2:41 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Capture the address window or file path to the clipboard with hotkey  (Read 13773 times)

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Capture the address window or file path to the clipboard with hotkey

I would like a software for

1. Capture the address of the selected active window to the clipboard with a definable hotkey
2. capture the file path selected to the clipboard with a definable hotkey

http://img577.imageshack.us/img577/6646/mozart26062012223822.png
Capture the address window or file path to the clipboard with hotkey

http://img27.imageshack.us/img27/4067/mozart26062012223835.png
Capture the address window or file path to the clipboard with hotkey


Best Regards

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
1. Capture the address of the selected active window to the clipboard with a definable hotkey

Since you have the active path displayed in the window's titlebar, you can do your first request like this:

Code: Autohotkey [Select]
  1. #q:: ; Win+Q, change to your liking.
  2. {
  3. }
  4. Return

2. capture the file path selected to the clipboard with a definable hotkey

The easiest way is probably:

Code: Autohotkey [Select]
  1. #c:: ; Win+C, change to your liking.
  2. {
  3.     Clipboard = %Clipboard%
  4. }
  5. Return


Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
1. Capture the address of the selected active window to the clipboard with a definable hotkey

Since you have the active path displayed in the window's titlebar, you can do your first request like this:

Code: Autohotkey [Select]
  1. #q:: ; Win+Q, change to your liking.
  2. {
  3. }
  4. Return

2. capture the file path selected to the clipboard with a definable hotkey

The easiest way is probably:

Code: Autohotkey [Select]
  1. #c:: ; Win+C, change to your liking.
  2. {
  3.     Clipboard = %Clipboard%
  4. }
  5. Return



Running
I can't believe would be so simpleeeeeeeeeeeeeee

 :-*

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
i am trying this first. But no results

; 1. Capture the address of the selected active window to the clipboard with a definable hotkey

; Since you have the active path displayed in the window's titlebar, you can do your first request like this:

; Formatted for Autohotkey with the GeSHI Syntax Highlighter [copy or print]
; Skwire
;   !#y:: ; no parece elegible ^#y en ctrl+Win+y, change to your liking. Pruebo con alt
^!u:: ;
    {
       WinGetTitle, Clipboard, A
    }
    Return

In the screenshots I selected the folder path, but the target is copy to the clipboard without it.
Only needed to select the windows folder.

I am doing something bad. Don't copy
I tried also win+1
but the clipboard have wrong.
It seems don't act the command
« Last Edit: June 26, 2012, 08:52 PM by Contro »

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Repeating

#q:: ; Win+Q, change to your liking.
    {
       WinGetTitle, Clipboard, A
    }
    Return

Go perfect

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Repeating

#c:: ; Win+C, change to your liking.
    {
       Clipboard = %Clipboard%
    }
    Return

don't go

I don't understand

clipboard = %clipboard%   ; Convert any copied files, HTML, or other formatted text to plain text.

I position the cursor over one file.

By example :

http://img40.imageshack.us/img40/572/mozart2806201233147.png
Capture the address window or file path to the clipboard with hotkey


After applying the script don't appear the clip in my Ditto Clipboard.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Try this:

Code: Autohotkey [Select]
  1. #c:: ; Win+C, change to your liking.
  2. {
  3.     SendInput, ^c
  4.     ClipWait, 2
  5.     Clipboard = %Clipboard%
  6. }
  7. Return

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
I'm not sure but I think what Contro is saying is:

a) If no file is selected, return the Window address field to the clipboard.
b) If a file is selected, return the full path of the file.

Feel free to ignore me if I'm wrong :)

Of course, with my non-knowledge of AutoHK you might have already answered the question, in which case feel free to  :trout:

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
I'm not sure but I think what Contro is saying is:

a) If no file is selected, return the Window address field to the clipboard.
b) If a file is selected, return the full path of the file.

Feel free to ignore me if I'm wrong :)

Of course, with my non-knowledge of AutoHK you might have already answered the question, in which case feel free to  :trout:

May be that what you are telling is what I must say.

 ;D

It's a good solution, because with one hotkey we can do all the tasks


Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Try this:

Code: Autohotkey [Select]
  1. #c:: ; Win+C, change to your liking.
  2. {
  3.     SendInput, ^c
  4.     ClipWait, 2
  5.     Clipboard = %Clipboard%
  6. }
  7. Return

Running to try
Best Regards
 :-*

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
A Strange thing. One time goes well. next time fails.

4wd is the best initial idea :

Possibilities with the assigned hotkey .
1. In the active window assigned hotkey copy the active window path to the clipboard
2. In the active window and one subfolder select copy the the subfolder path to the clipboard
3. In the active window and file select inside that folder or explorer window copy the file path to the clipboard.

 :P

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
I did not write any of this, (except _ExClip function and set a hotkey), it was written by Ascend4ant and Melba23 over on the AutoIt forum.

Thank them if you want to thank someone.

The hotkey is set for Shift+Alt+C, edit the code to change it to what you like.

  • If nothing is selected, the Explorer path is clipped.
  • If something is selected, its full path is clipped.
  • If multiple somethings are selected, only the first one is returned.

Code: AutoIt [Select]
  1. ; http://www.autoitscript.com/forum/topic/89833-windows-explorer-current-folder/page__st__40#entry973904
  2. #include <Array.au3>
  3.  
  4. HotKeySet('+!c', '_ExClip') ; Shift+Alt+C
  5.  
  6. Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ComErrFunc")
  7.  
  8.         Sleep(100)
  9.  
  10.  
  11. Func _ExClip()
  12.         $hExplr = WinActive("[REGEXPCLASS:(Explore|Cabinet)WClass]")
  13.         If $hExplr <> '' Then
  14.                 $aSelection = _ExplorerWinGetSelectedItems($hExplr)
  15.                 If $aSelection[0] = 0 Then
  16.                         If StringLeft($aSelection[1], 2) <> '::' Then ClipPut($aSelection[1])
  17.                 Else
  18.                         ClipPut($aSelection[2])
  19.                 EndIf
  20.         EndIf
  21.  
  22.  
  23.  
  24. ; ==========================================================================================================================
  25.  
  26. ; Func _ObjectSHFolderViewFromWin($hWnd)
  27. ;
  28. ; Returns an 'ShellFolderView' Object for the given Window handle
  29. ;
  30. ; Author: Ascend4nt, based on code by KaFu, klaus.s
  31. ; ==========================================================================================================================
  32.  
  33. Func _ObjectSHFolderViewFromWin($hWnd)
  34.     If Not IsHWnd($hWnd) Then Return SetError(1,0,0)
  35.     Local $oShell,$oShellWindows,$oIEObject,$oSHFolderView
  36.  
  37.     ; Shell Object
  38.     $oShell=ObjCreate("Shell.Application")
  39.     If Not IsObj($oShell) Then Return SetError(2,0,0)
  40.  
  41. ;   Get a 'ShellWindows Collection' object
  42.     $oShellWindows = $oShell.Windows()
  43.     If Not IsObj($oShellWindows) Then Return SetError(3,0,0)
  44.  
  45. ;   Iterate through the collection - each of type 'InternetExplorer' Object
  46.  
  47.     For $oIEObject In $oShellWindows
  48.         If $oIEObject.HWND = $hWnd Then
  49.             ; InternetExplorer->Document = ShellFolderView object
  50.             $oSHFolderView=$oIEObject.Document
  51.             If IsObj($oSHFolderView) Then Return $oSHFolderView
  52.             Return SetError(4,0,0)
  53.         EndIf
  54.     Next
  55.  
  56.     Return SetError(-1,0,0)
  57.  
  58. ; ==========================================================================================================================
  59. ; Func _ExplorerWinGetSelectedItems($hWnd)
  60. ;
  61. ;
  62. ; Author: klaus.s, KaFu, Ascend4nt (consolidation & cleanup, Path name simplification)
  63. ; ==========================================================================================================================
  64.  
  65. Func _ExplorerWinGetSelectedItems($hWnd)
  66.     If Not IsHWnd($hWnd) Then Return SetError(1,0,'')
  67.     Local $oSHFolderView
  68.     Local $iSelectedItems,$iCounter=2,$aSelectedItems[2] = [0, ""]
  69.  
  70.     $oSHFolderView=_ObjectSHFolderViewFromWin($hWnd)
  71.  
  72. ;   SelectedItems = FolderItems Collection object->Count
  73.     $iSelectedItems = $oSHFolderView.SelectedItems.Count
  74.  
  75.     Dim $aSelectedItems[$iSelectedItems+2]  ; 2 extra -> 1 for count [0], 1 for Folder Path [1]
  76.  
  77.     $aSelectedItems[0]=$iSelectedItems
  78. ;   ShellFolderView->Folder->Self as 'FolderItem'->Path
  79.     $aSelectedItems[1]=$oSHFolderView.Folder.Self.Path
  80.  
  81. ;   ShellFolderView->SelectedItems = FolderItems Collection object
  82.     $oSelectedFolderItems = $oSHFolderView.SelectedItems
  83.  
  84. #cs
  85.     ; For ALL items in an Explorer Window (not just the selected ones):
  86.     $oSelectedFolderItems = $oSHFolderView.Folder.Items
  87.     ReDim $aSelectedItems[$oSelectedFolderItems.Count+2]
  88. #ce
  89.  
  90.     For $oFolderItem In $oSelectedFolderItems
  91.         $aSelectedItems[$iCounter] = $oFolderItem.Path
  92.         $iCounter += 1
  93.     Next
  94.  
  95.     Return SetExtended($iCounter-2,$aSelectedItems)
  96. EndFunc   ;==>_ExplorerWinGetSelectedItems
  97.  
  98. Func _ComErrFunc($oError)
  99.     ConsoleWrite("COM Error occurred:"  & @CRLF & _
  100.         "Number: " & @TAB & $oError.number & @CRLF & _
  101.         "Windescription:" & @TAB & $oError.windescription & @CRLF & _
  102.         "Description is: " & @TAB & $oError.description & @CRLF & _
  103.         "Source is: " & @TAB & $oError.source & @CRLF & _
  104.         "Helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
  105.         "Helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
  106.         "Lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
  107.         "Scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
  108.         "Retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF)
  109. EndFunc   ;==>_ComErrFunc
« Last Edit: July 03, 2012, 09:30 AM by 4wd, Reason: For some reason I appear to be getting grumpier...it\'s not true...honest...maybe it\'s just the way I phrase things...or maybe I haven\'t had enough coffee... »

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
I did not write any of this, (except _ExClip function and set a hotkey), it was written by Ascend4ant and Melba23 over on the AutoIt forum.

Thank them if you want to thank someone.

The hotkey is set for Shift+Alt+C, edit the code to change it to what you like.

  • If nothing is selected, the Explorer path is clipped.
  • If something is selected, its full path is clipped.
  • If multiple somethings are selected, only the first one is returned.

Code: AutoIt [Select]
  1. ; http://www.autoitscript.com/forum/topic/89833-windows-explorer-current-folder/page__st__40#entry973904
  2. #include <Array.au3>
  3.  
  4. HotKeySet('+!c', '_ExClip') ; Shift+Alt+C
  5.  
  6. Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ComErrFunc")
  7.  
  8.         Sleep(100)
  9.  
  10.  
  11. Func _ExClip()
  12.         $hExplr = WinActive("[REGEXPCLASS:(Explore|Cabinet)WClass]")
  13.         If $hExplr <> '' Then
  14.                 $aSelection = _ExplorerWinGetSelectedItems($hExplr)
  15.                 If $aSelection[0] = 0 Then
  16.                         If StringLeft($aSelection[1], 2) <> '::' Then ClipPut($aSelection[1])
  17.                 Else
  18.                         ClipPut($aSelection[2])
  19.                 EndIf
  20.         EndIf
  21.  
  22.  
  23.  
  24. ; ==========================================================================================================================
  25.  
  26. ; Func _ObjectSHFolderViewFromWin($hWnd)
  27. ;
  28. ; Returns an 'ShellFolderView' Object for the given Window handle
  29. ;
  30. ; Author: Ascend4nt, based on code by KaFu, klaus.s
  31. ; ==========================================================================================================================
  32.  
  33. Func _ObjectSHFolderViewFromWin($hWnd)
  34.     If Not IsHWnd($hWnd) Then Return SetError(1,0,0)
  35.     Local $oShell,$oShellWindows,$oIEObject,$oSHFolderView
  36.  
  37.     ; Shell Object
  38.     $oShell=ObjCreate("Shell.Application")
  39.     If Not IsObj($oShell) Then Return SetError(2,0,0)
  40.  
  41. ;   Get a 'ShellWindows Collection' object
  42.     $oShellWindows = $oShell.Windows()
  43.     If Not IsObj($oShellWindows) Then Return SetError(3,0,0)
  44.  
  45. ;   Iterate through the collection - each of type 'InternetExplorer' Object
  46.  
  47.     For $oIEObject In $oShellWindows
  48.         If $oIEObject.HWND = $hWnd Then
  49.             ; InternetExplorer->Document = ShellFolderView object
  50.             $oSHFolderView=$oIEObject.Document
  51.             If IsObj($oSHFolderView) Then Return $oSHFolderView
  52.             Return SetError(4,0,0)
  53.         EndIf
  54.     Next
  55.  
  56.     Return SetError(-1,0,0)
  57.  
  58. ; ==========================================================================================================================
  59. ; Func _ExplorerWinGetSelectedItems($hWnd)
  60. ;
  61. ;
  62. ; Author: klaus.s, KaFu, Ascend4nt (consolidation & cleanup, Path name simplification)
  63. ; ==========================================================================================================================
  64.  
  65. Func _ExplorerWinGetSelectedItems($hWnd)
  66.     If Not IsHWnd($hWnd) Then Return SetError(1,0,'')
  67.     Local $oSHFolderView
  68.     Local $iSelectedItems,$iCounter=2,$aSelectedItems[2] = [0, ""]
  69.  
  70.     $oSHFolderView=_ObjectSHFolderViewFromWin($hWnd)
  71.  
  72. ;   SelectedItems = FolderItems Collection object->Count
  73.     $iSelectedItems = $oSHFolderView.SelectedItems.Count
  74.  
  75.     Dim $aSelectedItems[$iSelectedItems+2]  ; 2 extra -> 1 for count [0], 1 for Folder Path [1]
  76.  
  77.     $aSelectedItems[0]=$iSelectedItems
  78. ;   ShellFolderView->Folder->Self as 'FolderItem'->Path
  79.     $aSelectedItems[1]=$oSHFolderView.Folder.Self.Path
  80.  
  81. ;   ShellFolderView->SelectedItems = FolderItems Collection object
  82.     $oSelectedFolderItems = $oSHFolderView.SelectedItems
  83.  
  84. #cs
  85.     ; For ALL items in an Explorer Window (not just the selected ones):
  86.     $oSelectedFolderItems = $oSHFolderView.Folder.Items
  87.     ReDim $aSelectedItems[$oSelectedFolderItems.Count+2]
  88. #ce
  89.  
  90.     For $oFolderItem In $oSelectedFolderItems
  91.         $aSelectedItems[$iCounter] = $oFolderItem.Path
  92.         $iCounter += 1
  93.     Next
  94.  
  95.     Return SetExtended($iCounter-2,$aSelectedItems)
  96. EndFunc   ;==>_ExplorerWinGetSelectedItems
  97.  
  98. Func _ComErrFunc($oError)
  99.     ConsoleWrite("COM Error occurred:"  & @CRLF & _
  100.         "Number: " & @TAB & $oError.number & @CRLF & _
  101.         "Windescription:" & @TAB & $oError.windescription & @CRLF & _
  102.         "Description is: " & @TAB & $oError.description & @CRLF & _
  103.         "Source is: " & @TAB & $oError.source & @CRLF & _
  104.         "Helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
  105.         "Helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
  106.         "Lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
  107.         "Scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
  108.         "Retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF)
  109. EndFunc   ;==>_ComErrFunc

I'll try and comment.
 :-*

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
 :P

Wonderful.
Wonderfullllllllllllllllllllllllllllllllllll

http://img101.imageshack.us/img101/7251/besotene2.gif
Capture the address window or file path to the clipboard with hotkey
http://img101.imageshack.us/img101/7251/besotene2.gif
Capture the address window or file path to the clipboard with hotkey
http://img101.imageshack.us/img101/7251/besotene2.gif
Capture the address window or file path to the clipboard with hotkey
http://img101.imageshack.us/img101/7251/besotene2.gif
Capture the address window or file path to the clipboard with hotkey

gabrielko

  • Participant
  • Joined in 2012
  • *
  • default avatar
  • Posts: 1
    • View Profile
    • Donate to Member
Re: Capture the address window or file path to the clipboard with hotkey
« Reply #14 on: October 02, 2012, 11:41 AM »
This may or may not be significant, it's totally up to you to decide I really did get a quick fix with Long Path Tool. http://PathTooDeep.com  :D