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.

Revisions

  1. @ethack ethack revised this gist Dec 29, 2020. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion TypeClipboard.md
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ Why can't you just paste the contents you ask? Sometimes pasting just doesn't w
    * 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.
    The Windows version is written in [AutoHotKey](https://www.autohotkey.com/) and easily compiles to an executable. It's a single line script that maps Ctrl-Shift-V to type the clipboard.

    ```ahk
    ^+v::Send {Raw}%Clipboard%
    @@ -36,6 +36,8 @@ The following is a version that just "pastes" immediately to the active window.
    xclip -selection clipboard -out | tr \\n \\r | xdotool type --clearmodifiers --delay 25 --file -
    ```

    I saved this to a script and then mapped the script to a hotkey using Gnome's custom keyboard shortcuts.

    ## OSX
    The Mac version is writtern in AppleScript.

  2. @ethack ethack revised this gist Dec 29, 2020. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion TypeClipboard.md
    Original file line number Diff line number Diff line change
    @@ -26,6 +26,7 @@ Explanation of the flags used:
    * `tr \\n \\r` replaces newlines with carriage returns to ensure they don't get missed in some applications.
    * `selectwindow` allows you to pick a window to send text to. This means you don't have to have the window active when you run the command.
    * `windowfocus` focuses the selected window. Most apps I tried would ignore keystroke events if they weren't in focus.
    * `--clearmodifiers` makes sure that no modifier keys are pressed before typing.
    * `--delay 25` was the best balance between speed and not missing keystrokes in the applications I was using. This shouldn't be noticable for short text, but makes a difference with longer text.
    * `--window $@` means that keystrokes will only be sent to that window. If you focus a different window the typed keystrokes won't suddenly be sent to your new window.
    * `--file -` reads from stdin.
    @@ -55,4 +56,5 @@ Otherwise, you can use a third party program that lets you set custom hotkeys su

    ## Credits:
    * @Indigo744 for the suggestion to use `{Raw}` in the Windows version
    * @L3vi47h4N for the Linux version
    * @L3vi47h4N for the Linux version
    * @brabster for the `--clearmodifiers` suggestion in the Linux version
  3. @ethack ethack revised this gist Dec 29, 2020. 2 changed files with 20 additions and 2 deletions.
    19 changes: 17 additions & 2 deletions TypeClipboard.md
    Original file line number Diff line number Diff line change
    @@ -14,10 +14,25 @@ The Windows version is written in AutoHotKey and easily compiles to an executabl
    ```

    ## Linux
    The following should work on Linux, provided you have `xdotool` and `xclip` installed.
    The following should work on Linux, provided you have `xdotool` and `xclip` installed. This version lets you select the window you want to send the keystrokes to.

    ```
    sh -c 'sleep 1.0; xdotool type "$(xclip -o -selection clipboard)"'
    xclip -selection clipboard -out | tr \\n \\r | xdotool selectwindow windowfocus type --clearmodifiers --delay 25 --window %@ --file -
    ```

    Explanation of the flags used:
    * `xclip -selection clipboard` gets the contents of the clipboard.
    * `-out` writes the text to stdout.
    * `tr \\n \\r` replaces newlines with carriage returns to ensure they don't get missed in some applications.
    * `selectwindow` allows you to pick a window to send text to. This means you don't have to have the window active when you run the command.
    * `windowfocus` focuses the selected window. Most apps I tried would ignore keystroke events if they weren't in focus.
    * `--delay 25` was the best balance between speed and not missing keystrokes in the applications I was using. This shouldn't be noticable for short text, but makes a difference with longer text.
    * `--window $@` means that keystrokes will only be sent to that window. If you focus a different window the typed keystrokes won't suddenly be sent to your new window.
    * `--file -` reads from stdin.

    The following is a version that just "pastes" immediately to the active window.
    ```
    xclip -selection clipboard -out | tr \\n \\r | xdotool type --clearmodifiers --delay 25 --file -
    ```

    ## OSX
    3 changes: 3 additions & 0 deletions type_clipboard.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    #!/bin/bash

    xclip -selection clipboard -out | tr \\n \\r | xdotool selectwindow windowfocus type --clearmodifiers --delay 25 --window %@ --file -
  4. @ethack ethack renamed this gist Mar 18, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @ethack ethack revised this gist Nov 7, 2018. 5 changed files with 16 additions and 11 deletions.
    17 changes: 15 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -6,12 +6,21 @@ Why can't you just paste the contents you ask? Sometimes pasting just doesn't w
    * 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.

    ```ahk
    ^+v::Send %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.

    ```applescript
    @@ -27,4 +36,8 @@ osascript -e 'tell application "System Events" to keystroke the clipboard as tex
    To bind this to a keyboard shortcut you have several options. Sticking with builtin OSX utilities you can follow this guide.
    - http://blog.fosketts.net/2010/08/09/assign-keyboard-shortcut-applescript-automator-service/

    Otherwise, you can use a third party program that lets you set custom hotkeys such as: BetterTouchTool, Keyboard Maestro, or Hammerspoon
    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
    2 changes: 1 addition & 1 deletion type_clipboard.ahk
    Original file line number Diff line number Diff line change
    @@ -2,4 +2,4 @@
    SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
    #NoTrayIcon ; Hide the tray icon

    ^+v::Send %Clipboard%
    ^+v::Send {Raw}%Clipboard%
    1 change: 0 additions & 1 deletion type_clipboard.exe.b64
    0 additions, 1 deletion not shown because the diff is too large. Please use a local Git client to view these changes.
    5 changes: 0 additions & 5 deletions type_clipboard.scpt
    Original file line number Diff line number Diff line change
    @@ -1,5 +0,0 @@
    --tell application "System Events"
    -- keystroke the clipboard as text
    --end tell

    tell application "System Events" to keystroke the clipboard as text
    2 changes: 0 additions & 2 deletions type_clipboard.sh
    Original file line number Diff line number Diff line change
    @@ -1,2 +0,0 @@
    #!/bin/bash
    osascript -e 'tell application "System Events" to keystroke the clipboard as text'
  6. @ethack ethack revised this gist Mar 2, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions type_clipboard.exe.b64
    1 addition, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
  7. @ethack ethack revised this gist Jun 17, 2016. 1 changed file with 30 additions and 0 deletions.
    30 changes: 30 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    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.

    ```ahk
    ^+v::Send %Clipboard%
    ```

    The Mac version is writtern in AppleScript.

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

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

    ```bash
    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.
    - http://blog.fosketts.net/2010/08/09/assign-keyboard-shortcut-applescript-automator-service/

    Otherwise, you can use a third party program that lets you set custom hotkeys such as: BetterTouchTool, Keyboard Maestro, or Hammerspoon
  8. @ethack ethack created this gist May 24, 2016.
    5 changes: 5 additions & 0 deletions type_clipboard.ahk
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    #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%
    5 changes: 5 additions & 0 deletions type_clipboard.scpt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    --tell application "System Events"
    -- keystroke the clipboard as text
    --end tell

    tell application "System Events" to keystroke the clipboard as text
    2 changes: 2 additions & 0 deletions type_clipboard.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    #!/bin/bash
    osascript -e 'tell application "System Events" to keystroke the clipboard as text'