Copying contents of a text file

Is there a was I can have Finder (or System Events?) copy the contents of a .txt file to the clipboard? What I want to do is have a bunch of text files that can be read from, and then pasted. So, it’d be something like this:

tell app "System Events" tell process "Finder" copy contents of "~/Desktop/message1.txt" to clipboard keystroke "v" using command down
This is actually for a quote scripting program for IRC. If you have any better ideas for a quote scripting program then having a bunch of text files in a folder (makeshift database), then please share it. :slight_smile:

Sorry if I’m thick, but your code snippit doesn’t make it clear what you want to do. FYI, it’s easy to get text to the clipboard from a selection or from a document, and it’s easy to keystroke “v” using {command down} too, but the “paste” has to go somewhere, and the the text being pasted has to come from somewhere and neither of those is clear. Finally, it’s easy to simply read text into an AppleScript and then write it somewhere else, but if other programs are involved, we have to know what they are.

Think through what you want to do a bit more and then ask again.

Hi,

You don’t need ui scripting for just text. You might want to use copy and paste if you watn to save formatting. Here’s for just plain text:

set f to ((path to desktop as string) & “message1.txt”) as alias
set t to read f
set the clipboard to t

There are different ways to create the reference f.

gl,

Here’s something else to consider:

choose file without invisibles
do shell script "/usr/bin/pbcopy < " & quoted form of POSIX path of result