Keyboard shortcut to paste Windows shortcuts

Page 2 of 2 FirstFirst 12

  1. Posts : 25
    Windows 10 (1903)
    Thread Starter
       #11

    das10 said:
    Just in case you didn't know , If you are still using the following line in your script, have a look in your AHK Scripts Directory for the Shortcuts
    My AHK script is stored in C:\Users\%username%\documents.

    I replaced "%A_ScriptDir%" by different paths or I let as it was, nothing changed.
      My Computer


  2. Posts : 3,274
    Win10
       #12

    Sorry, I was only looking at the script without having tried it. However, having just tried it on both Windows 10 and XP, it does not work in Windows 10, but works perfectly in XP, so some AHK functions don't seem to be getting anywhere in Win 10 with regard to the splitting of the paths, etc.

    My apologies.
      My Computers


  3. Posts : 25
    Windows 10 (1903)
    Thread Starter
       #13

    das10 said:
    Sorry, I was only looking at the script without having tried it. However, having just tried it on both Windows 10 and XP, it does not work in Windows 10, but works perfectly in XP, so some AHK functions don't seem to be getting anywhere in Win 10 with regard to the splitting of the paths, etc. My apologies.
    Ok thanks for the info.
      My Computer


  4. Posts : 3,274
    Win10
       #14

    So I have modified the AHK script using some of Win10's new functions from information gathered from this thread

    FileCreateShortcut does not work in Windows 10 - AutoHotkey Community

    and it seems to work as follows:

    Working directory is set to your User Documents folder.
    I have inserted a couple of message boxes (commented out currently; you can use them to see if you want/need to make adjustments) to enable you to see some information when you press Ctrl B.
    So when you select multiple files using Ctrl C and then use Ctrl B, the Shortcuts of those files are created in your Documents folder.
    You can modify the script as you want (I am not an expert in AHK, I just used the previously posted script and the information in the link above and modified it).
    For your information, I used AutoHotkeyU64.exe version1.1.27.2.
    In case yoou didn't know, you have to press on the AutoHotKey tray icon and click "Reload Script" if and when you modify the script.


    ;Code:

    Code:
    #SingleInstance, Force
    #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
    #Warn ; Enable warnings to assist with detecting common errors.
    SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
    AutoTrim, off
    
    
    SetWorkingDir, %A_MyDocuments%      ;    or change to hard coded link eg C:\tests    which must already exist
    
    
    ~^c:: ; (~)[hotkey passthrough] | (^)[ctrl key] | (c)[c key]
    
    
    Array := [] ; Temporary array for holding parsed clipboard contents
    sleep 100
    
    	clipboard := ; clear clipboard contents before starting
    sleep 50
    	Send ^c ; send keystroke to copy to clipboard
    	ClipWait ; wait for clipboard to be populated
    	Loop, parse, clipboard, `n, `r ; loop through clipboard, seperate at newline
    	{
    	    Array.Push(A_LoopField) ; push current line of clipboard to array
    	}
    return
    
    
    ^b:: ; (^)[ctrl key] | (b)[b key]
    	address := ActiveFolderPath() ; call function to get path in ACTIVE explorer window
    	for index, element in Array ; loop through array
    		{
    		; for current iteration..
    		SplitPath, element, name, dir, ext, name_no_ext, drive ; for each item in array, split the path to corresponding variables 
    		
    		
    ;		msgbox, SOURCE %dir%\%name%
    ;		msgbox, DESTINATION %A_Workingdir%\%name%.lnk
    
    
    shortcut = %A_Workingdir%\%name%.lnk
    target = %dir%\%name%
    
    WshShell := ComObjCreate("WScript.Shell")
    oShellLink := WshShell.CreateShortcut(shortcut)
    oShellLink.TargetPath := target
    oShellLink.Save()
    
    			}	
    
    return
    
    ; Author Scoox
    ; https://autohotkey.com/board/topic/70960-detect-current-windows-explorer-location/
    
    ActiveFolderPath(WinTitle="A")
    {
        WinGetClass Class, %WinTitle%
        If (Class ~= "Progman|WorkerW") ;desktop
            WinPath := A_Desktop
        ;Else If (Class ~= "(Cabinet|Explore)WClass") ;all other Explorer windows
        Else ;all other windows
        {
            WinGetText, WinPath, A
            RegExMatch(WinPath, "Address:.*", WinPath)
            WinPath := RegExReplace(WinPath, "Address: ") ;remove "Address: " part
        }
    
        WinPath := RegExReplace(WinPath, "\\+$") ;remove single or double  trailing backslash
        If WinPath ;if path not empty, append single backslash
            WinPath .= "\"
        Return WinPath
    }


    Hope thathelps you towards a working solution, if not, I am out of ideas
      My Computers


  5. Posts : 25
    Windows 10 (1903)
    Thread Starter
       #15

    Ok I figured out that hAirypAulsAck's script actually works. I misunderstood that the Windows shortcuts were sent to the directory set in "SetWorkingDir".

    The one you slightly modified works even better as it only pastes the last copied file(s).

    Now I just need to find out how to paste Windows shortcuts in the active window rather the window set in "SetWorkingDir" line.
      My Computer


  6. Posts : 3,274
    Win10
       #16

    Try commenting out the "SetWorkingDir" line. (insert ; at its beginning)
    and change this line of code (at around line 40) also :

    from
    shortcut = %A_Workingdir%\%name%.lnk

    to
    shortcut = %dir%\%name%.lnk


    Also, as I mentioned previously, you can also use these variables on the msgbox line (temporarily uncomment them) to see what values variables have at that point.


    I too had to modify hAirypAulsAck's script to prevent the duplication of Shortcuts of previously copied files, although I still can't make it work in Win 10 for some odd reason/s.

    Overall, the FileCreateShortcut function is easier to understand within the context of AHK and hAirypAulsAck script if it works for you can be modified thus:

    Following his posted script ad verbatim,

    At line 5, Comment out the following code (insert a ; at its beginning) ie.
    ;SetWorkingDir %A_ScriptDir%

    At line 7, the array code must come after the copy command (this clears the array every time you press ^C and prevents duplications of previous file copies) ie.
    ~^c::
    Array := []

    Between lines 24 and 25 insert the code below to get shortcuts in the same File/s Directory
    SetWorkingDir %dir%
    Last edited by das10; 24 Jul 2019 at 18:00.
      My Computers


  7. Posts : 3,274
    Win10
       #17

    Slightly modified; so now again using "File Manager" only , "Ctrl + C" to copy multiple files in one folder; go to folder where you want the shortcuts to those files and press "Ctrl + B" .

    Works ok overall, but test on a few files before using generally, especially if you make shortcuts to files which have the same names from different folders, in which case the old shortcut gets overwritten with the new one.

    Code:
    ; select multiple files in a dir-Ctrl+Copy-goto destination dir-press Ctrl+B to get shortcuts of those files
    #SingleInstance, Force
    #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
    ;#Warn ; Enable warnings to assist with detecting common errors.
    SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
    AutoTrim, off
    ;SetWorkingDir, %A_MyDocuments%      ;    or change to hard coded link eg C:\tests    which must already exist
    
    ~^c:: ; (~)[hotkey passthrough] | (^)[ctrl key] | (c)[c key]
    
    Array := [] ; Temporary array for holding parsed clipboard contents
    ;sleep 50
    	clipboard := ; clear clipboard contents before starting
    ;sleep 50
    	Send ^c ; send keystroke to copy to clipboard
    	ClipWait ; wait for clipboard to be populated
    	Loop, parse, clipboard, `n, `r ; loop through clipboard, seperate at newline
    	{
    	    Array.Push(A_LoopField) ; push current line of clipboard to array
    	}
    return
    
    ^b:: ; (^)[ctrl key] | (b)[b key]
    
    for window in ComObjCreate("Shell.Application").Windows  ; get folder for destination
    	desdir = % window.Document.Folder.Self.Path
    ;	MsgBox, % window.Document.Folder.Self.Path	
    ;	MsgBox,%desdir%
    	
    address := ActiveFolderPath() ; call function to get path in ACTIVE explorer window
    		for index, element in Array ; loop through array
    		{
    		; for current iteration..
    		SplitPath, element, name, dir, ext, name_no_ext, drive ; for each item in array, split the path to corresponding variables 
    shortcut = %desdir%\%name%.lnk
    target = %dir%\%name%
    WshShell := ComObjCreate("WScript.Shell")
    oShellLink := WshShell.CreateShortcut(shortcut)
    oShellLink.TargetPath := target
    oShellLink.Save()
    			}	
    return
    ; Author Scoox
    ; https://autohotkey.com/board/topic/70960-detect-current-windows-explorer-location/
    ActiveFolderPath(WinTitle="A")
    {
        WinGetClass Class, %WinTitle%
        If (Class ~= "Progman|WorkerW") ;desktop
            WinPath := A_Desktop
        ;Else If (Class ~= "(Cabinet|Explore)WClass") ;all other Explorer windows
        Else ;all other windows
        {
            WinGetText, WinPath, A
            RegExMatch(WinPath, "Address:.*", WinPath)
            WinPath := RegExReplace(WinPath, "Address: ") ;remove "Address: " part
        }
        WinPath := RegExReplace(WinPath, "\\+$") ;remove single or double  trailing backslash
        If WinPath ;if path not empty, append single backslash
            WinPath .= "\"
        Return WinPath
    }
      My Computers


  8. Posts : 16
    Windows 10
       #18

    [QUOTE=das10;1679619]Slightly modified; so now again using "File Manager" only , "Ctrl + C" to copy multiple files in one folder; go to folder where you want the shortcuts to those files and press "Ctrl + B" .

    It doesn't work in windows 10?
    ¯\_(ツ)_/¯ maybe i was in linex or ubundu
    I could have sworn I made it while in windows 10..

    silly me, i was in windoze 10.. cheap imitation knockoffs..


    but really, did you read my OP? Watch gifv demonstration video?

    Code:
    ^b::
        address := ActiveFolderPath() ; call function to get path in ACTIVE explorer window
        for index, element in Array ; loop through array
        {
            ; for current iteration..
            SplitPath, element, name, dir, ext, name_no_ext, drive ; for each item in array, split the path to corresponding variables 
            FileCreateShortcut, %element%, %address%%name_no_ext%.lnk ; create shortcut for Target = %element% and LinkDest = %address%%name_no_ext%.lnk [IN PATH JUST RECEIVED FROM ABOVE]
        }    
    return
    initially I used ControlGet to grab the edit1 control (which is the address bar), but opted to go with the fucntion that I added at the bottom because it had handling for cases where more than one explorer window was open.
    Keyboard shortcut to paste Windows shortcuts-image.png
    NOTE: AutoHotkey handles the clipboard in at least 2 different ways. One, is standard clipboard file operations of copy/cut and paste, the other, is to get a list of all the items full path that were sent to the clipboard.

    The script took the items with their full paths, split them up line by line (automatically), then I sent them to an array element by element by watching for the line breaks. We now have an array with each element being the full path of one of the items sent to clipboard.

    Before we begin to iterate through the array, we get the contents of the address bar of the active explorer window, and set that to the destination that the links would be sent to.

    Dude may have been having a problem by taking sources from different directories, where that would take more work for a script, not much, but mine wasn't designed to do that
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 05:26.
Find Us




Windows 10 Forums