Skip to content

Instantly share code, notes, and snippets.

@prgarg007
Forked from ethack/TypeClipboard.md
Created May 15, 2024 17:47
Show Gist options
  • Save prgarg007/10fd815ee08d527ca858b0ea70c0dfaf to your computer and use it in GitHub Desktop.
Save prgarg007/10fd815ee08d527ca858b0ea70c0dfaf to your computer and use it in GitHub Desktop.
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.

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 %Clipboard%

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

#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 %Clipboard%
--tell application "System Events"
-- keystroke the clipboard as text
--end tell
tell application "System Events" to keystroke the clipboard as text
#!/bin/bash
osascript -e 'tell application "System Events" to keystroke the clipboard as text'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment