문제

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!

도움이 되었습니까?

해결책

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)

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top