AutoHotkey: Make shortcut file from clipboard contents: Difference between revisions

From TotalcmdWiki
Jump to navigation Jump to search
(v1.00)
 
(v1.01 - added checking for the second window to arrive)
Line 16: Line 16:
*/ ; --> <code><pre>
*/ ; --> <code><pre>
; ////////////////////////////////////////////////////////////////
; ////////////////////////////////////////////////////////////////
; // MkNewShortcut_from_Clipboard.ahk v1.00 -  (W) StatusQuo 2008
; // MkNewShortcut_from_Clipboard.ahk v1.01 -  (W) StatusQuo 2008
; ////////////////////////////////////////////////////////////////
; ////////////////////////////////////////////////////////////////
; // Make new shortcut (lnk/URL) using actual clipboard information.
; // Make new shortcut (lnk/URL) using actual clipboard information.
Line 30: Line 30:
WinWaitActive, ahk_class #32770,,3
WinWaitActive, ahk_class #32770,,3
if Errorlevel
if Errorlevel
{ MsgBox, Waiting for NewLink-Window timed out.
{ MsgBox, *** Error: `n`nWaiting for CreateLink-Window timed out.
Exit
Exit
}
}
ControlSetText, Edit1, %sURL%
ControlSetText, Edit1, %sURL%
; ControlSend,  Edit1, {END} ; jump to end, showing file name to user (+ emulating real input behaviour)
; ControlSend,  Edit1, {END} ; jump to end, showing file name to user (+ emulating real input behaviour)
Sleep, 300 ; let user get a quick look at the URL
Sleep, 250 ; let user get a quick look at the URL
ControlClick,  Button3 ; ControlSend,    Edit1, {ENTER}
ControlClick,  Button3 ; ControlSend,    Edit1, {ENTER}


sFileName = %Clipboard%
sFileName = %Clipboard%
{
{ ; Clipboard = Internet URL
; Clipboard = Internet URL
; StringGetPos: zero-based, first char is #0
; StringGetPos: zero-based, first char is #0
StringGetPos, iPos, sFileName, /, R
StringGetPos, iPos, sFileName, /, R
Line 57: Line 56:
StringMid, sFileName, sFileName, iPos + 2
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
}
}



Revision as of 01:40, 29 January 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
;