AppleScript to paste clipboard into current application

6,506

Solution 1

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.

Solution 2

I ran your script and it worked fine for me. Which OS are you using?

Another option is to use have AppleScript run a shell script accessing PlainClip's command line option:

tell application "System Events" to tell (name of application processes whose frontmost is true) to do shell script "'/Applications/Plain Clip.app/pc' -v"
Share:
6,506

Related videos on Youtube

Zade
Author by

Zade

I make stuff

Updated on September 18, 2022

Comments

  • Zade
    Zade over 1 year

    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}
    
    • Zade
      Zade over 11 years
      yep, no dice...I'll update the code though
    • Oliver Salzburg
      Oliver Salzburg over 11 years
      I realized later that {} seems to be the notation for a list of keys. So I guess it would just be optional in this case. Nevermind :)
  • Joel Reid
    Joel Reid over 11 years
    I have System Events type out the clipboard for me all the time, into text fields that don't allow pasting. For example, I have long, random-character passwords for some encrypted disk images stored in a password manager, but DiskImageMounter doesn't allow pasting.
  • Zade
    Zade over 11 years
    This works within the AppleScript editor if I click Run. However, I've set a keyboard shortcut to run this, and when I press the shortcut, weird things happen. It doesn't paste the clipboard. Furthermore, I want it to remove leading/trailing spaces/tabs from each line, as well as blank lines and invisible control characters, like Plain Clip does. Is this possible? Thanks!
  • BallpointBen
    BallpointBen over 5 years
    If you use this, you have to be careful not to press any modifier keys while the clipboard is being typed out.