I’m trying to cobble together an applescript that reads a txt file, then copies the text to the clipboard.
I managed to come up with the script below, but it only seems to copy the first couple of words and then cuts off the end. The text files will usually only contain a single URL, but it cuts those short too.
tell application "Finder"
set theFile to the selection as alias
open for access theFile
set fileContents to (read theFile)
close access theFile
end tell
set the clipboard to fileContents
Anyone know why it’s only copying just the beginning?
try
tell application "Finder" to set theFile to item 1 of (get selection)
set the clipboard to (read (theFile as alias))
on error
display dialog "Nothing selected" buttons {"Cancel"} default button "Cancel"
end try
The problem of not all the text being copied appears to be a bug with Mountain Lion and selecting a file on the desktop, but I still appreciate the help cleaning up the script. Thanks again
tell application "Finder"
set theFile to item 1 of (get selection)
set fileRef to open for access (theFile as alias)
set fileContents to (read fileRef)
close access fileRef
end tell
set the clipboard to fileContents