Edit in WriteRoom from DEVONthink Pro

I recently purchased DEVONthink Pro and WriteRoom, and I encountered a need for a smooth workflow. I wrote a few Applescripts that, when combined with Quicksilver triggers, create a nearly seamless interoperation between the two apps.

After installing WriteRoom 2.0 beta, I enabled the "Edit in WriteRoom" functionality in the WriteRoom preferences. Next, I created a hotkey for this menu item in the "Keyboard & Mouse" System Preferences pane. Finally, I closed and reopened DEVONthink Pro. It is important that you use the same hotkey that I used for the script to work: Command-Control-Shift-E. It's a bit convoluted, but it seemed to have the most success working in a large number of applications in my testing.

To simply edit the currently selected DEVONthink record in WriteRoom (also works with records that are already being edited), use the following code: -- Author: sunetos -- Site: adamia.com

tell application "DEVONthink Pro" set win to first think window

try
    set sel to selection in win
    set rec to first item in sel
    set myid to name in rec
    open window for record (rec)
on error

end try

activate
delay 0.1

tell application "System Events"
    tell process "DEVONthink pro"
        keystroke "e" using {command down, control down, shift down}
    end tell
end tell

end tell

For a more powerful script that lets you create a new text record from anywhere ("modeless" functionality), supply the name, launch a WriteRoom editor, monitor the process, commit changes back to DEVONthink, save the record, and finally close the record, use the code below: -- Author: sunetos -- Site: adamia.com

set recordPath to "/Projects/adamia/pending"

tell application "DEVONthink Pro" activate display dialog "What is the name of the new article?" default answer "pending" set newRecordName to text returned of result

delay 0.1

set rec to get record at recordPath
set newRecord to create record with {name:newRecordName, type:txt} in rec

delay 0.1

open window for record (newRecord)

activate
delay 0.1

tell application "System Events"
    tell process "DEVONthink pro"
        keystroke "e" using {command down, control down, shift down}
    end tell
end tell

end tell

--tell application "WriteRoom" to activate -- in case the hotkey wasn't setup, avoid infinite loop

repeat if not (isWriteRoomDone()) then -- Wait for WriteRoom to launch exit repeat else delay 0.5 end if end repeat

repeat if (isWriteRoomDone()) then -- Wait for WriteRoom session to finish exit repeat else delay 0.5 end if end repeat

on isWriteRoomDone() set writeRoomDone to false set writeRoomProcesses to 0 tell application "System Events" set writeRoomProcesses to count (every process whose displayed name is "WriteRoom") end tell if writeRoomProcesses = 1 then set writeRoomDone to false else set writeRoomDone to true end if return (writeRoomDone) end isWriteRoomDone

tell application "System Events" tell process "DEVONthink pro" keystroke "s" using {command down} delay 0.1 keystroke "w" using {command down} end tell end tell

Obviously, your DEVONthink Pro database should not have a group with the path "/Projects/adamia/Pending," so change that first line to the path of the group where you would like these new records to be stored.

If you have any questions or addition requests, just leave a comment. To finish it up, just create a Quicksilver trigger that calls the new script, and you should have a solid workflow for DEVONthink and WriteRoom for easily writing new content whenever you wish!

Comments

Thanks

Thanks for the comment! I just realized that a previous beta of WriteRoom included WriteOut 2.0 beta for WriteRoom 2.0, so I started messing with it. However, I'm not sure how I actually want the workflow to work. My first thought is to have DEVONthink store RTFs and have it transform from RTF to Markdown for WR, then convert again back to RTF for storing back in DEVONthink. But the more I thought about it, the more I'm thinking I should keep Markdown in DEVONthink for portability purposes. What do you think?

a d a m

Great Work!

Thank you so much for this great work. I too was trying to figure out how to edit in WriteRoom while preserving the original database article. These scripts do the trick.

I look forward to the Markdown update when it is available.

Robert

Post new comment

The content of this field is kept private and will not be shown publicly.