Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Transfer clipboard contents via AppleScript System
This hint made me think of another way to copy clipboard contents to another computer: Use AppleScript.

Copy the below code into Script Editor. Replace ShortUserName, Password, and 10.15.1.12 with the destination machine's short user name, the user's password, and the machine's IP address.

When you run the script, your clipboard contents will be placed onto the destination machine's clipboard.
property theMachine : "eppc://ShortUserName:Password@10.15.1.12"

tell application "System Events"
  try
    -- this works in Tiger
    set xfr_clip to (the clipboard as text)
  on error
    try
      -- this works in Earlier Versions
      set xfr_clip to «class ktxt» of ((the clipboard as text) as record)
    on error err_msg
      display dialog err_msg
    end try
  end try
end tell

tell application "System Events" of machine theMachine
  set the clipboard to ((xfr_clip) as text)
end tell
[robg adds: To make this work, you need to do two things. First, visit System Preferences: Sharing on the destination machine, and enable Remote Apple Events. Second, and this bit threw me for a while (thanks Kirk!), the destination machine must also have Folder Actions enabled -- otherwise, there's no System Events process, and the script dies. Go to Applications -> AppleScript, and double-click on Folder Actions Setup to enable Folder Actions. Once these two things are done, the script works great.]
    •    
  • Currently 3.20 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
 
[17,044 views]  

Transfer clipboard contents via AppleScript | 3 comments | Create New Account
Click here to return to the 'Transfer clipboard contents via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Works perfectly - thanks!
Authored by: Lunatic Prods on Oct 13, '05 07:50:10AM

Brilliantly simple! Thankyou ... (I wish I was clever!) ... I have other options for synchronising pasteboards (synergy, teleport) ... but what I like about this simple script is that it's a 'one-time send clipboard' solution, rather than a 'longer-term two-way clipboard sharing' solution.

Did I say this was a wonderful site?

;o)



[ # ]
Transfer clipboard contents via AppleScript
Authored by: dpouliot on Oct 14, '05 07:30:07AM

awesome script!
Any way to modify this to transfer items other than text? Like copying and pasting files to and from each desktop? I tried stripping off "as text" in 2 locations, but that didn't work.



[ # ]
Transfer clipboard contents via AppleScript
Authored by: lar3ry on Oct 14, '05 12:10:00PM

How about this:

$ pbcopy | ssh username@othersystem

Short, sweet, and doesn't require Applescript.

(I think pbcopy/pbpaste are the most useful tools included in the OS X toolset, and I wonder why no Linux system has come up with something similar other than xcutsel and xcb).



[ # ]