Elias
Elias

Reputation: 237

Applescript to "paste" clipboard

I am working on an Applescript to paste what was last copied to any current field. It is to be used with VoiceOver and the key code way (only way I know how) does not work all of the time.

    tell application "System Events" to key code 9 using command down

    say "paste"

Upvotes: 13

Views: 21844

Answers (3)

Wowfunhappy
Wowfunhappy

Reputation: 268

tell application "myApp" to activate

tell application "System Events" to tell application process "myApp"
    click menu item "Paste" of menu "Edit" of menu bar item "Edit" of menu bar 1
end tell

Obviously, replace myApp with the name of your app.

Advantages:

  • Only targets a specific app (safer!)
  • Will work even if the user set a custom keyboard shortcut for Paste
  • Text is pasted instantly (unlike using keystroke).

Upvotes: 1

ccpizza
ccpizza

Reputation: 31801

There is a direct way to access the clipboard via the the clipboard keyword:

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

Reference:

Upvotes: 6

jweaks
jweaks

Reputation: 3792

I use keystroke:

tell application "System Events" to keystroke "v" using command down

I'm not aware of an error you should get, so you'll have to share.

Upvotes: 25

Related Questions