Skip to content

Instantly share code, notes, and snippets.

@ethack ethack/README.md
Last active Sep 2, 2019

Embed
What would you like to do?
Scripts that simulate typing the clipboard contents. Useful when pasting is not allowed.

It "types" the contents of the clipboard.

Why can't you just paste the contents you ask? Sometimes pasting just doesn't work.

  • One example is in system password fields on OSX.
  • Sometimes you're working in a VM and the clipboard isn't shared.
  • Other times you're working via Remote Desktop and again, the clipboard doesn't work in password boxes such as the system login prompts.
  • Connected via RDP and clipboard sharing is disabled and so is mounting of local drives. If the system doesn't have internet access there's no easy way to get things like payloads or Powershell scripts onto it... until now.

Windows

The Windows version is written in AutoHotKey and easily compiles to an executable. It's a single line script that maps Ctrl-Shift-V to type the clipboard.

^+v::Send {Raw}%Clipboard%

Linux

The following should work on Linux, provided you have xdotool and xclip installed.

sh -c 'sleep 1.0; xdotool type "$(xclip -o -selection clipboard)"'

OSX

The Mac version is writtern in AppleScript.

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

The equivalent one-liner from the command line would be:

osascript -e 'tell application "System Events" to keystroke the clipboard as text'

To bind this to a keyboard shortcut you have several options. Sticking with builtin OSX utilities you can follow this guide.

Otherwise, you can use a third party program that lets you set custom hotkeys such as: BetterTouchTool, Keyboard Maestro, or Hammerspoon

Credits:

  • @Indigo744 for the suggestion to use {Raw} in the Windows version
  • @L3vi47h4N for the Linux version
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
#NoTrayIcon ; Hide the tray icon
^+v::Send {Raw}%Clipboard%
@Indigo744

This comment has been minimized.

Copy link

commented Jun 19, 2018

I would suggest you to use

^+v::Send {Raw}%Clipboard%

Otherwise some expression will be interpreted... Like {Enter} to Enter, ^c to CTRL+C...
See https://autohotkey.com/docs/commands/Send.htm

@ghost

This comment has been minimized.

Copy link

commented Jun 25, 2018

With a typical Linux install, the following works (requires xclip and xdotool):
sh -c 'sleep 1.0; xdotool type "$(xclip -o -selection clipboard)"'

@nanoDBA

This comment has been minimized.

Copy link

commented Aug 23, 2018

Still trying to figure out why this awesome idea to simulate typing the clipboard contents isn't working in a local PowerShell console host (version 5.1.17134.228 on Windows 10) for me - it does work in the ISE console and in CMD.EXE. Also works fine in PowerShell Core 6.01.

Works fine in RDP sessions to PowerShell 5.1.14393.2273 as well.

@ypid-geberit

This comment has been minimized.

Copy link

commented Sep 20, 2018

@nanoDBA I would assume that this is because Windows tries protect processes running under a different user from being influenced by your current user. (I say tries because I am very aware how real isolation looks like -> Qubes OS.) You should be able to fix that by running the script as admin.

Ref: andreas-hofmann/neoqwertz#1

@ethack

This comment has been minimized.

Copy link
Owner Author

commented Nov 7, 2018

Thanks for the contributions @Indigo744 and @L3vi47h4N!

I had no idea people were commenting here.

@haakonstorm

This comment has been minimized.

Copy link

commented Sep 1, 2019

I need a way to be able to paste special characters, so that they are typed, on macOS.
text \t text2
is written literally.
Tips?

@ethack

This comment has been minimized.

Copy link
Owner Author

commented Sep 1, 2019

@haakonstorm if the special characters are in the clipboard they get typed correctly. For instance if I copy "text text2" and then use the script to type the clipboard it types it out as "text text2" (where the actual tab character is between the text). If you're looking to define a string with escape sequences like "\t" or "\n" in Applescript then I would have tried \t like you did as well. Or look at if you can define characters as hex codes or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.