AppleScript to paste clipboard into current application

applescriptpastetext formatting

I thought this would be simple…

I want an AppleScript that launches Plain Clip and then pastes the clipboard into the current document where the cursor is. My script launches Plain Clip (a format-clearing app that doesn't steal focus), but it doesn't paste the new clipboard. Any ideas?

tell application "Plain Clip" to activate
delay 1
tell application "System Events" to tell (name of application processes whose frontmost is true) to keystroke "v" using {command down}

Best Answer

  • Since you're stripping the clipboard down to plaintext anyway, you could perhaps finish by scripting the keyboard rather than scripting Plain Clip.

    do shell script "pbpaste |textutil -convert txt -stdin -stdout -encoding 30 |pbcopy"
    tell application "System Events" to keystroke (the clipboard)
    

    p.s. that first line does the same thing that Plain Clip does.
    p.p.s. scripting System Events requires access for assistive devices to be on.

  • Related Question