Skip to content

Instantly share code, notes, and snippets.

@Vaisakhkm2625
Last active November 12, 2024 23:09
Show Gist options
  • Save Vaisakhkm2625/c8c61ef2fca3a345fb1e28f80bd766d8 to your computer and use it in GitHub Desktop.
Save Vaisakhkm2625/c8c61ef2fca3a345fb1e28f80bd766d8 to your computer and use it in GitHub Desktop.
clipboard type

Type from clipboard

A simple script to simulate keypresses to type copied text, in places where pasting is not enabled and don't have access to install new apps

(Remote or local virtual desktops, various online forms, ssh connection through old terminal emulators etc)

😅 A lot of people are using this, but couldn't get anyone to star this repo...

image

Windows

$wshell = New-Object -ComObject wscript.shell;$txt='';foreach ($element in $(Get-Clipboard)){$element=$element -replace '[+^%~(){}]','{$0}';$element= -join($element,'{ENTER}');echo $element;$txt = -join($txt,$element);};sleep 4; $wshell.SendKeys($txt);

run this in powershell, and within 4 sec, place cursor at where you want to type all out

prettyfiled code

$wshell = New-Object -ComObject wscript.shell;
$txt='';
foreach ($element in $(Get-Clipboard)){
  $element=$element -replace '[+^%~(){}]','{$0}';
  $element= -join($element,'{ENTER}');
  echo $element;
  $txt = -join($txt,$element);
};
sleep 4; $wshell.SendKeys($txt);

Linux

For wayland users

start the ydotoold service as demon (this is for security reason on wayland, )

systemctl start ydotoold; // for socket errors try YDOTOOL_SOCKET='/tmp/.ydotool_socket' ydotool type 'hi'

To type from clipboard

sleep 3;ydotool type $(wl-paste)

To type from file

sleep 4;ydotool type -f <filename>

For x11 users

sleep 4; xdotool type "$(xclip -o -selection clipboard)"

MacOS

For apple users, here is a AppleScript with works the same

delay 4

tell application "System Events" to keystroke (the clipboard as text)

https://stackoverflow.com/a/63468725/15070114

inspired by -
https://christitus.com/clickpaste

@Vaisakhkm2625
Copy link
Author

Vaisakhkm2625 commented Nov 12, 2024

wayland toggleable script

change !# lines to #!/bin/bash in case you are not using nixos

#!/usr/bin/env nix-shell
#!nix-shell -i bash -p wl-clipboard procps ydotool notify-send

TEMP_FILE="/tmp/cliptype"

if ! pgrep -x "ydotoold" >/dev/null; then
	notify-send "ydotoold not running" -t 500
	exit 1
fi

if [ -e "$TEMP_FILE" ]; then
	rm /tmp/cliptype
	notify-send "stopping" -t 500
	pkill -x ydotool
        exit
fi

sleep 5
wl-paste >/tmp/cliptype
ydotool type -f /tmp/cliptype -d 40
rm /tmp/cliptype

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment