AutoHotkey: Make shortcut file from clipboard contents: Difference between revisions
Jump to navigation
Jump to search
(v1.01 - added checking for the second window to arrive) |
(added link back to Autohotkey) |
||
Line 73: | Line 73: | ||
ControlSetText, Edit1, %sFileName% ; ControlSendRaw, Edit1, %sFileName% | ControlSetText, Edit1, %sFileName% ; ControlSendRaw, Edit1, %sFileName% | ||
ControlSend , Edit1, {END} ; let cursor jump to end, emulating real input behaviour | ControlSend , Edit1, {END} ; let cursor jump to end, emulating real input behaviour | ||
;</pre></code> | ;</pre></code>Back to [[AutoHotkey]] |
Revision as of 17:27, 20 April 2008
Make a new shortcut (*.LNK for local targets, *.URL for internet URLs),
- -taking the clipboard's contents as target address and
- -trying to auto-detect the file name for *.lnk/*.url
Leaves only the last RETURN key press to the user, the rest is automated.
Related links:
; ////////////////////////////////////////////////////////////////
; // MkNewShortcut_from_Clipboard.ahk v1.01 - (W) StatusQuo 2008
; ////////////////////////////////////////////////////////////////
; // Make new shortcut (lnk/URL) using actual clipboard information.
; // Tested on Win2k SP4, supposed to run well on later versions.
; //
; // Thanks to icfu for pointing me to appwiz.cpl function
; ////////////////////////////////////////////////////////////////
sRunCmd = rundll32.exe appwiz.cpl`,NewLinkHere %A_WorkingDir%\
sURL = %Clipboard%
Run, %sRunCmd%
WinWaitActive, ahk_class #32770,,3
if Errorlevel
{ MsgBox, *** Error: `n`nWaiting for CreateLink-Window timed out.
Exit
}
ControlSetText, Edit1, %sURL%
; ControlSend, Edit1, {END} ; jump to end, showing file name to user (+ emulating real input behaviour)
Sleep, 250 ; let user get a quick look at the URL
ControlClick, Button3 ; ControlSend, Edit1, {ENTER}
sFileName = %Clipboard%
{ ; Clipboard = Internet URL
; StringGetPos: zero-based, first char is #0
StringGetPos, iPos, sFileName, /, R
if (iPos < 0)
{ ; Clipboard = local path
StringGetPos, iPos, sFileName, \, R
}
if (iPos < 0)
{ ; Clipboard = useless
Exit
}
if (iPos + 1 >= StrLen(sFileName))
{ ; last char is (back)slash, no filename found in clipboard
Exit
} else {
StringMid, sFileName, sFileName, iPos + 2
}
}
;- wait for system to process the link and proceed to link file name
;- check, if system proceeded to second window, asking for link file name; if not: wait
Loop, 15
{ ControlGetText, sTmp, Edit1
if sTmp!=%sURL%
Break
Sleep, 100
}
if sTmp=%sURL%
{ MsgBox, *** Error: `n`nFirst CreateLink window still active, aborting.
Return ; Exit
}
ControlSetText, Edit1, %sFileName% ; ControlSendRaw, Edit1, %sFileName%
ControlSend , Edit1, {END} ; let cursor jump to end, emulating real input behaviour
;
Back to AutoHotkey