Question

I am incredibly new to Applescript, first of all, so bear with me.

I currently have a plain-text file in a Dropbox folder. The file is set to be filled with text (and only text). I am trying to create an Automator workflow (or an Applescript script) that will read the contents from the text file, and write the contents to the clipboard. This way, I can copy text on my iOS devices, paste them into the plain-text file in Dropbox, and then use my mac (and this script), to paste the text to the mac. Basically, using Dropbox to sync clipboards between OS X and iOS.

I imagine the Applescript can't be more than a few lines, but I haven't found the proper way to write it. Any help is appreciated!

Was it helpful?

Solution

set the_file to choose file
set the_text to (do shell script "cat " & quoted form of (POSIX path of the_file))
set the clipboard to the_text

or alternately using only AS:

set the_file to choose file
set the clipboard to (read the_file)

(This second piece of code throws an End of file error for me for certain files and I'm not sure why, so I'd use the first one)

OTHER TIPS

In Automator, you can combine the actions:

  1. Files & Folders › Get specified Finder items
  2. Text › Combine text files
  3. Utilities › Copy to clipboard

to achieve what you're after. You may also want to skip "Get specified Finder items" and instead make your Automator workflow a Folder Action, which will pass files into your workflow as they are added to a folder you specify.

Separately, there may be a better way overall to achieve your end goal. What are you really after? (See XY Problem.)

† Despite the name, "Combine text files" can be used to read the contents of a single file. It takes one or more files as input and gives rich text as output.

Extending duozmo's solution keeping points #2 & 3 same. Ideally, make an automator service so that it is available upon right clicking single or multiple files.

Here is the screenshot of such a service:

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top