Created
December 28, 2023 01:50
-
-
Save trackd/cc2674c742a7c483ea771ac2c6eb7439 to your computer and use it in GitHub Desktop.
prototype something something
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Add-ClipboardProtocolHandler { | |
# clipboard:// | |
$custom = Get-Command "$env:temp\customclip.exe" -CommandType Application -ErrorAction 'Stop' | |
$uri = 'clipboard' | |
if (!(Test-Path "HKCU:\Software\Classes\$uri")) { | |
New-Item "HKCU:\Software\Classes\$uri" | |
} | |
Set-ItemProperty "HKCU:\Software\Classes\$uri" '(Default)' "URL:$uri Protocol" | |
Set-ItemProperty "HKCU:\Software\Classes\$uri" 'URL Protocol' '' | |
if (!(Test-Path "HKCU:\Software\Classes\$uri\shell")) { | |
New-Item "HKCU:\Software\Classes\$uri\shell" | |
} | |
if (!(Test-Path "HKCU:\Software\Classes\$uri\shell\open")) { | |
New-Item "HKCU:\Software\Classes\$uri\shell\open" | |
} | |
if (!(Test-Path "HKCU:\Software\Classes\$uri\shell\open\command")) { | |
New-Item "HKCU:\Software\Classes\$uri\shell\open\command" | |
} | |
Set-ItemProperty "HKCU:\Software\Classes\$uri\shell\open\command" '(Default)' "$($custom.Path) %1" | |
} | |
Add-ClipboardProtocolHandler | |
function writeclip { | |
param( | |
[Parameter(Mandatory,Position = 0)] | |
[String]$Link, | |
[Parameter(Mandatory,Position = 1)] | |
[string]$String | |
) | |
return "`e]8;;clipboard://{0}/`e\{1}`e]8;;`e\" -f $String, $Link | |
} | |
writeclip -Link "click me" -String "test 12345 spaces" | |
# requires windows powershell to compile binary file | |
throw 'this part needs to be run from windows powershell' | |
$c = @' | |
using System; | |
using System.Windows.Forms; | |
class Program | |
{ | |
[STAThread] | |
static void Main(string[] args) | |
{ | |
if (args.Length > 0) | |
{ | |
string text = string.Join(" ", args); | |
string prefix = "clipboard://"; | |
if (text.StartsWith(prefix)) | |
{ | |
text = text.Substring(prefix.Length); | |
} | |
if (text.EndsWith("/")) | |
{ | |
text = text.Substring(0, text.Length - 1); | |
} | |
Clipboard.SetText(text); | |
} | |
} | |
} | |
'@ | |
Add-Type -TypeDefinition $c -ReferencedAssemblies System.Windows.Forms -OutputAssembly "$env:temp\customclip.exe" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment