Copying text and images from a record using Applescript?

I’m interested in using Tofu (homepage.mac.com/asagoo/tofu/) as a reader with DEVONthink Pro, and I’d like to write an Applescript to automate the transfer of data from a displayed record into Tofu. Manual copying and pasting from DT Pro to Tofu works great with both rtf and web archives–styled text and images both come across and display nicely. I’ve written an Applescript that will open up Tofu and paste the clipboard into it, and that works fine. However, using Applescript I can’t seem to copy anything other than plain text from the displayed record in DT Pro onto the clipboard. I’ve tried a number of DT Pro’s Applescript commands and all I get is plain text. I’ve also tried to select all and copy the content of the displayed record using Applescript GUI scripting to call the edit menu commands directly. That produces an NSReceiverEvaluationScriptError (4), but I may be losing the selection context when the script runs.

Does anyone have any suggestions on how to copy the complete styled text and image display from a DT Pro viewer or document window to the clipboard using Applescript? If I can get there I can get that into Tofu.

Jim Harrison
Univ. of Virginia

(ps. also posted in “Tips & Tricks”)

AppleScript doesn’t seem to support the transfer of rich text between applications. Therefore, your only way out would be to “hack” it using the clipboard. But I have no idea how to do that in AppleScript without resorting to calling Objective-C methods inside it.

This subject has come up before (and I have been burned by it as well with the Automator actions). Maybe we should all file bug reports at Apple?

I’m also interested about the possibility of copying rich text from one application to another without GUI scripting, but have no idea how to do it.

(My problem is:: given a a Safari window, make a rich text file out of it, edit the file with textedit, and send it to DTPro? I think about: Capture the page safari in DTPro as HTML, convert to rich text, export, edit with textedit, reimport, but i’d like to do it in a quicker way.)

Thanks

you have to export the record to to a temp folder and script the other application to open or import it. i believe it’s the only way to move rtf from one app to another. also make sure to leave feedback for apple that it should be possible to set the clipboard to rtf styled text with applescript.

Thanks, Wooden Brain, I’ll do it this way, and send feedback to apple. If I understand correctly, DTPro 2 will allow to edit documents without exporting. (In fact, we are close to that: opening a document with textedit creates a temp file, that the script could import into the DTdatabase before closing. But I don’t think that the “open with textedit” of DT can be inserted into an applescript.)

Alb

The next release (v1.1) will support something like…


set myPath to "/tmp"
set myFile to export record myRecord to myPath
tell application "TextEdit" to open (myFile as POSIX file)

But at the moment you have to do this:


set myPath to "/tmp"
export record myRecord to myPath
set myFile to myPath & "/" & (filename of myRecord)
tell application "TextEdit" to open (myFile as POSIX file)

Thanks, Christian, this works as exected, and is sufficient for my needs.

Alb