Context Menu Clipboard Access

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Stinkfoot9
Posts: 74
Joined: 29 May 2022, 12:17

Context Menu Clipboard Access

Post by Stinkfoot9 » 11 Nov 2024, 16:07

I had posted a different version of this before but i nested all the clipboard contents into one var and it caused a lot of problems. This version used multiple variables.

!v opens menu with last 9 clipboard contents. Click on selection or use number pad 1-9.

Code: Select all

#Notrayicon

OnClipboardChange("ClipChanged")

Menu, Tray, Tip, ContextCB
Menu, Tray, NoStandard ; remove standard Menu items
Menu, Tray, Add, &Edit , Edit
Menu, Tray, Add, &Exit, Exit

ClipChanged(Type) {
If (TogClipGate != 1)  
	If Clipboard is not space
		GoSub, ClipMenu
}
return

Edit:
Run, Notepad++.exe "%A_scriptfullpath%"
return

Exit:
Exitapp
Return


ClipMenu:     
{
Tooltip, Copied
Menu, MyMenu, add,,                                   
Menu, Mymenu, DeleteAll
Loop, 8 {
	Index1 := (9 - A_index)
	Index2 := (10 - A_index)
	ClipVar%Index2% := ClipVar%Index1%
	}
;| Clipboard := Trim(Clipboard,"`r`n" "`t" A_space) ; meant to trim native clipboard but interferes with copying folders in explorer
Clipvar1 := Clipboard    
Loop, 9 {
	ClipTrim := RegExReplace(Clipvar%A_index%, "\s", " ")
	ClipVarSub := SubStr(ClipTrim,1, 50)	
	If (Clipvar%A_index% != "")
		Menu, MyMenu, add, %A_index%. %Clipvarsub%, MenuHand                      	
	}
Sleep 600
Tooltip
}
return 

!v::        
If ClipVar1 is not space        
	Menu, MyMenu, Show   
Else {
	Tooltip, Empty
	sleep 600
	tooltip
	}
return

MenuHand:                                                                                                
Global TogClipGate = 1                                          
sleep 175
clipboard := ClipVar%A_thismenuItemPos%
send, ^v
Sleep 175
TogClipGate = 0
return

n00b
Posts: 45
Joined: 24 May 2016, 16:42

Re: Context Menu Clipboard Access

Post by n00b » 09 Dec 2024, 17:31

Thank you for the updated script.

Copying a single ampersand “&” leads to Error. Nonexistent menu item.
You could prevent the error dialog and thread termination by adding, Add Menu, MyMenu, UseErrorLevel

Post Reply

Return to “Scripts and Functions (v1)”