Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applescript: Read contents from text file, copy contents to clipboard

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!

like image 248
user2690304 Avatar asked Dec 15 '22 07:12

user2690304


1 Answers

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)

like image 109
scohe001 Avatar answered Jan 13 '23 11:01

scohe001