AutoHotkey: Make shortcut file from clipboard contents

From TotalcmdWiki
Revision as of 01:24, 21 January 2008 by StatusQuo (talk | contribs) (v1.00)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.00  -  (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, Waiting for NewLink-Window timed out.
	Exit
}
ControlSetText, Edit1, %sURL%
; 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
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
	}
}

ControlSetText, Edit1, %sFileName%	; ControlSendRaw, Edit1, %sFileName%
ControlSend   , Edit1, {END}	; let cursor jump to end, emulating real input behaviour
;