The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Scripts for Integrating OmniFocus with DEVONthink 2 (http://forums.omnigroup.com/showthread.php?t=12734)

RobTrew 2009-06-09 05:10 AM

Scripts for integrating OmniFocus with DEVONthink 2
 
As an adjunct to OmniFocus, DEVONthink 2 rewards investigation.
It is highly scriptable, and works well as a powerfully indexed repository and archive of the various kinds of files, links, and references that may be needed for each OmniFocus project.

Here is a set of four scripts which illustrate the scope for automating this interaction.

[URL="http://bit.ly/UaNPhw"]Download[/URL]

I am using them for both:

[I]Sending to Devonthink,[/I]

[B]Save2DevonAsTXT.scpt[/B] exports whatever is currently selected in OmniFocus (task, project, folder), as a text file, to a corresponding DEVONthink 2 project folder.
The text file is in TaskPaper format. The DT2 folder has the same path as the selected Omnifocus project or folder. This DT2 folder is automatically created, if it does not already exist.

[B]Save2DevonAsOO3.scpt[/B] exports whatever is currently selected in OmniFocus (task, project, folder), as an OmniOutliner 3 file, to a corresponding DEVONthink 2 project folder.
The .oo3 file contains columns for task properties such as Context, Start, Due, Completed, Duration, Flagged. The OmniOutliner checkbox is set according to the OF task Done property. The DT2 folder has the same path as the selected Omnifocus project or folder. This DT2 folder is automatically created, if it does not already exist.

[I]and fetching from Devonthink.[/I]

[B]OpenProjFolderInDevon.scpt[/B] opens a folder, in DEVONthink 2, for the currently selected OmniFocus project. (The DT2 folder is automatically created, if it does not already exist).

[B]OpenProjNotesInDevon.scpt[/B] opens a project notes file (stored in the matching DEVONthink 2 folder) for the selected OmniFocus project. The notes file is an Omnioutliner 3 document. (The DT2 folder and .oo3 file are automatically created, if they do not already exist).

(The latter two scripts were inspired by Jim Harrison's excellent scripts, which use the Finder rather than DEVONthink 2 [URL="http://jhh.med.virginia.edu/main/OmniFocusScripts"]http://jhh.med.virginia.edu/main/OmniFocusScripts[/URL])

[I]A PS on DEVONthink[/I]
I was originally attracted to DEVONthink by its automatic OCR conversion of photocopy-based PDFs, and by the sheer flexibility and focus with which it can search (well beyond the scope of Spotlight) across a whole database of PDFs and other documents. (One could digress on its integration with DevonAgent, and on searches beyond the scope of Google – suffice it so say that this also rewards investigation if research is part of what you do).

As an alternative to the Finder for organizing folders and files, I particularly appreciate its contents panes, which remove much of the friction involved in seeing beyond the file name, particularly during searches.

For instructions on installing Applescripts, see:
[URL="http://forums.omnigroup.com/showthread.php?t=7453"]http://forums.omnigroup.com/showthread.php?t=7453[/URL]

RobTrew 2009-06-09 03:28 PM

Just uploaded [URL="http://bit.ly/UaNPhw"]version 002[/URL] which gives the DEVONthink records clickable links back to the corresponding projects/tasks in Omnifocus.

steve 2009-06-10 02:37 PM

Hi Rob,

This is an exciting development in my workflow. Everything works very well except for OpenProjNotesInDevon.scpt. It sounds like it is supposed to put the 003 document in a notes file inside of the corresponding project folder. For me, the project goes to the global inbox and it has a dot in the document name. Each time I hit it I get a new file even if I already have a note file started for that project. Chances are I have a funky set-up on my machine.

Thanks for posting these!

RobTrew 2009-06-10 03:13 PM

Good - I'm glad you find this useful.

[QUOTE=steve;61000]
Everything works very well except for OpenProjNotesInDevon.scpt. It sounds like it is supposed to put the 003 document in a notes file inside of the corresponding project folder. For me, the project goes to the global inbox and it has a dot in the document name. Each time I hit it I get a new file even if I already have a note file started for that project. Chances are I have a funky set-up on my machine.[/QUOTE]

Sounds like there may be a timing issue. The notes file comes in through the virtual inbox and should then be moved to the appropriate folder. There seems to be slight a delay before the programming interface can see the initial copy in the Inbox.

I have amended the script to allow for this delay.

connie 2009-06-15 01:42 AM

Hello,
this seems like a great idea. Unfortunately, I'm useless when it come to scripts. Each time a I try to use the script it asks me if I want to create a new database. I don't want to create a new database, I would just like to add the folder to an existing database. Can you tell me what I need to add to the script?

thanks

RobTrew 2009-06-15 09:19 AM

[QUOTE=connie;61174]I don't want to create a new database, I would just like to add the folder to an existing database. Can you tell me what I need to add to the script?[/QUOTE]

In each of the four scripts the first two statements are:
[IMG]http://farm4.static.flickr.com/3303/3629726404_a9ff0572f3.jpg[/IMG]

You will need to use the OS X Script Editor to amend these lines, so that they give the path and name of your existing DEVONthink database.

If your database is in a path descending from the [username]/Documents folder, then it will be enough to amend the database name (and any sub-path beyond your Documents folder) between quotes in the second statement.

For example:
[IMG]http://farm4.static.flickr.com/3398/3629948248_278273cd96.jpg[/IMG]

connie 2009-06-17 02:20 AM

Thanks for this. Still not there yet, tho. I store my databases in dropbox. Does that matter? Here is the response I get when I try to it.

AppleScript reported the following error:
DEVONthink Pro got an error: Can’t get parent id 16257 of database 3

thanks again

RobTrew 2009-06-17 08:01 AM

[QUOTE=connie;61323]I store my databases in dropbox. Does that matter? Here is the response I get when I try to it.

AppleScript reported the following error:
DEVONthink Pro got an error: Can’t get parent id 16257 of database 3[/QUOTE]


The trick is to specify the [B]full[/B] path of the database.

If you were using the OS X Drop Box sub-folder of your ~/Public folder, you would need:

[I]property strDocsPath : (path to public folder as text) & "Drop Box"[/I]

If you are using the commercial [URL="http://www.getdropbox.com/"]Dropbox[/URL] service, you will need:

[I]property strDocsPath : (path to home folder as text) & "Dropbox"[/I]

RobTrew 2009-06-17 01:07 PM

Have [URL="http://bit.ly/UaNPhw"]updated[/URL] the script for opening .003 project notes in DEVONthink - simplifying the internals and making it a little faster when it initially creates the notes file.

marshallj 2009-06-20 10:48 AM

Open Project Notes doesn't open or create a note
 
Hi, I'm particularly interested in the third script that opens a project folder and creates an .oo3 file if one isn't already created. The script creates a folder structure but doesn't create an oo3 file. Just an empty folder. Any idea what I'm doing wrong?

Thanks for these scripts... They're great.

RobTrew 2009-06-20 01:52 PM

Hi, I'm glad the scripts are useful.

[QUOTE=marshallj;61454]I'm particularly interested in the third script that opens a project folder and creates an .oo3 file if one isn't already created. The script creates a folder structure but doesn't create an oo3 file. Just an empty folder. Any idea what I'm doing wrong? [/QUOTE]

On this, three initial questions:[LIST=1][*]Are you sure you're using the right script ? ([I]OpenProjFolderInDevon[/I] does indeed just open a folder - the one you want is [I]OpenProjNotesInDevon[/I])[*]Is OmniOutliner Professional installed on your system ?[*]Are you getting any error messages ?[/LIST]

marshallj 2009-06-20 05:20 PM

[QUOTE=RobTrew;61459]Hi, I'm glad the scripts are useful.



On this, three initial questions:[LIST=1][*]Are you sure you're using the right script ? ([I]OpenProjFolderInDevon[/I] does indeed just open a folder - the one you want is [I]OpenProjNotesInDevon[/I])[*]Is OmniOutliner Professional installed on your system ?[*]Are you getting any error messages ?[/LIST][/QUOTE]

Hi,

Yes, I have OO v3.8, DTPO pb5, and OF 1.6.1

There are no error messages and I did run the right script. Both of the above mentioned scripts do the same thing. They create a folder for the project that is selected in OF but neither creates an OO document.

I wonder what the problem could be? I installed all four scripts and they run fine except for the "OpenProjNotes" one. Does "Omnifocus Notes" need to be the default database?

I don't know much about scripts other than how to install them.

Is there another way to create the linkback to the OF project?

whpalmer4 2009-06-20 10:07 PM

[QUOTE=marshallj;61461]Hi,

Yes, I have OO v3.8, DTPO pb5, and OF 1.6.1
[/QUOTE]

You have OmniOutliner or OmniOutliner [b]Professional[/b]? The scripts try to invoke the latter...

marshallj 2009-06-20 10:38 PM

Professional

Hmmm

RobTrew 2009-06-20 10:58 PM

[QUOTE=marshallj;61461]Is there another way to create the linkback to the OF project?[/QUOTE]

The simplest way to get a linkback from the Devonthink folder to a corresponding OF project is to drag and drop the OF project to the DT folder. This will create a record containing a link.

Re the script, if there are no error messages, I would begin by removing the scripts from the OF toolbar, downloading them again, and installing them afresh. (An earlier version imported the .oo3 file through the DT2 Inbox, which was associated with a delay, and could have caused your problem. You should have version 4 of the Project Notes script).

Then, I suggest you watch OmniOutliner 3 Pro fairly closely:
[LIST][*]If OO Pro is closed when you run the script, does the script cause it to launch ?[*]If you look at the [B]File > Open Recent[/B] list in the OO Pro menu system (before and after running the script) do you see any difference ?[*]If the [B]File > Open Recent[/B] list shows a file matching the project name, where is it ? (Try opening it, or searching with Spotlight)[/LIST]
Finally, you are welcome to send me a message through the [URL="http://forums.omnigroup.com/private.php"]Private Messages[/URL] system of this board (see link at top right), to continue the discussion off-line.

bpwhistler 2009-08-19 09:42 AM

I get the following error when I run the script OpenProjNotesInDevon.scpt:

"The script 'OpenProjNotesInDevon.scpt' could not complete.

AppleScript reported the following error: Finder got an error: Can’t get alias "MacBook HD:Users:Bretts:Library:Application Support:OmniOutliner 3:Templates:Default.oo3template"."

Any help would be great

bpwhistler 2009-08-19 12:02 PM

Let me start by saying these scripts are an excellent idea, and after examining your workflow description on the DT forums, I can anticipate their usefulness. I use all 3 of these applications extensively. Except for a few minor "glitches" (which I outline below) the OpenProjFolderInDevon and Save2DevonAsOO3 scripts work as expected.

The following are the problems I'm having with the scripts. I'm running all but the SaveToDevonAsTXT script:

1. If DT is open prior to running a script that sends a .OO3 file, a new DT window is opened for the "OF Notes" database regardless of whether it is already open or not. If I run a script multiple times, I get a new "OF Notes" database window for each time I send an .OO3 to it via the script. Very annoying. At one point I had over 20 DT windows open. If the database is open in DT but currently not the active database, can the script change to the "OF Notes" database without opening a new window? Or if the "OF Notes" database isn't open, but DT is, can the script open the "OF Notes" database in the current window?
2. When DT opens with one of these 3 scripts, the file tree is not visible...even if the .OO3 file just added is visible. I have to switch to another database and then back to "OF Notes" or close and relaunch DT for the file tree to become visible.
3. When making a new .OO3 file with the Save2DevonAsOO3 script, an untitled .OO3 file is created in addition to the .OO3 file to be stored in DT. It is left open & blank on OO after the OF -> DT .OO3 is saved to the DT database. If many files are sent to DT as .OO3 files from OF, this can be quite annoying and cumbersome. Is there anyway to auto-delete (or just not produce) these untitled files?
4. When running the OpenProjNotesInDevon script, an error is produced: "The document “Untitled 2” could not be saved as “• Misc. get organized notes.oo3”." When I acknowledge the error...no file is saved to the "OF Notes" database and 2 untitled .OO3 files are left open in OO. Untitled 1 is the "extra" .OO3 file mentioned in #3 above. So an "extra" .OO3 file is created with both scripts that produce these file types.

I was wondering about "streamlining" the interface. I know next to nothing about AppleScript, but I do have limited Toolbar real estate. Is it possible to include Boolean type operators in the scripting. Instead of having 3 separate scripts, have 1 that works differently under different situations.
-If nothing is highlighted: just open the "OF Notes" database in DT
-If a project is highlighted: open that file in the "OF Notes" database or open the database and create the folder if it is not present
-If an action is highlighted: convert to a .OO3 file and place in the proper "OF Notes" database file or create the file if it doesn't exist and then place the .OO3 file in it.

RobTrew 2009-08-19 09:10 PM

On streamlining the toolbar - no need to install the script icons there - you can assign keystrokes to each of the scripts.

Will try to reproduce your error message when I get time - not something I have seen.

Generally, the scripts are posted "as is" - in the form in which I use them myself, and you are very welcome to modify them to suit your own work-flow (though you might find some of your goals are hard to achieve with the existing scripting interfaces, particularly on the DT side).

[COLOR="White"]--[/COLOR]

Greg Jones 2009-08-21 03:56 AM

RobTrew, I just started playing with these scripts this morning and I think they could be useful to me. I do have one question that I hope you know without asking you to research and test the scripts. If not, I'll poke around and see if I can find the answer.

As is, the scripts create and/or expect to find the OF folders at the root level of the DT database. That is, if I have the following structure in OF:

Folder: 'Researcher' that contains:
Project: 'Research Project A'
Project: 'Research Project B'

Then executing the 'Save2DevonAs003' script on the project 'Research Project A' will create these new groups (folders) in the DT database:

'Research Database.dtBase2' root:
Group: 'Researcher'
Sub-group: 'Research Project A'

This organization works well if one is using a dedicated DT database (as example, OmniFocus Notes) to link to OmniFocus. What I would like to do is link to a DT group in an existing database, and group all groups and files created by the scripts to be organized in one master group. So my structure would ideally look like this:

'Research Database.dtBase2' root:
Group: 'OmniFocus Research Projects'
Sub-group: 'Researcher'
Sub-group: 'Research Project A'

So, this has been a rather wordy way of asking, can the script(s) be easily edited so that the scripts create/find everything in a user-specified group in the database rather than at the database's root level?

Thanks!

RobTrew 2009-08-21 04:34 AM

[QUOTE=Greg Jones;65027]can the script(s) be easily edited so that the scripts create/find everything in a user-specified group in the database rather than at the database's root level?[/QUOTE]

Should be no problem - you will just need to experiment with adjusting the path strings.

[COLOR="White"]--[/COLOR]

bpwhistler 2009-08-21 04:51 AM

Rob Trew...I'm moderately new to these forums, so apologize if I wasn't clear. I realize the scripts are as is. I wasn't asking if you would modify them for me, but rather if the behavior I described was what you were seeing, and if so can it be modified by tweaking the script. So without reproducing my VERY wordy prior post...is it possible to change the producing of an "extra" untitled OO file, stop the opening of a new DT window (rather than just making the database active in the existing window), and making the DT file tree visible on the script launching it? The same with regards to "streamlining." I wasn't asking you to streamline it for me...but rather if it was possible to streamline it in the manner I described.

If so, I will attempt to modify the scripts myself. If not I won't waste my time (or yours by asking questions about your script that you know are impossible).

If you don't have the time to address these...also understandable. I know everyone on these forums is busy...or else they wouldn't be using OF to it's most efficient function.

RobTrew 2009-08-21 01:27 PM

[QUOTE=bpwhistler;65034]is it possible to change the producing of an "extra" untitled OO file[/QUOTE]

This is not by design, and I haven't seen it myself. Will try to reproduce it when I get a chance.

[QUOTE=bpwhistler;65034]is it possible to ... stop the opening of a new DT window (rather than just making the database active in the existing window), and making the DT file tree visible[/QUOTE]

Certainly desirable, but my recollection is that the DevonThink scripting interface doesn't make this possible at present. More an issue for the DT forum than this one, perhaps.

[COLOR="White"]--[/COLOR]

ben_worthington 2009-08-23 12:18 AM

path
 
Hi,

These scripts are very useful. I want to change the path so that the DT database resides in my Dropbox folder.

I am probably being immensely stupid but I cant see how to change the script to get this to work. I cant even see where the path is defined in the script! I can guarantee that even if I did know this, I'd write the wrong path and the script wouldn't run.

I'd be really grateful if someone could give me an idiot's guide to doing this.

Many thanks

Ben

RobTrew 2009-08-23 07:00 AM

[QUOTE=ben_worthington;65091]These scripts are very useful. I want to change the path so that the DT database resides in my Dropbox folder.[/QUOTE]

Not sure if you have noticed an earlier exchange in this thread:

[URL="http://forums.omnigroup.com/showpost.php?p=61326&postcount=8"]http://forums.omnigroup.com/showpost.php?p=61326&postcount=8[/URL]

ben_worthington 2009-08-23 07:53 AM

[QUOTE=RobTrew;65099]Not sure if you have noticed an earlier exchange in this thread:

[URL="http://forums.omnigroup.com/showpost.php?p=61326&postcount=8"]http://forums.omnigroup.com/showpost.php?p=61326&postcount=8[/URL][/QUOTE]

Thanks Rob. My Dropbox folder resides in my home folder ie Users/benworthington/Dropbox.

I amended the script to read as below

property strDocsPath : (path to home folder as text) --path to ~Users/benworthington/Dropbox/OmniFocus Notes.dtBase2
property strDevonDatabase : "OmniFocus Notes" -- name of Devonthink Database

The script runs but ignores the Dropbox folder, creating the database in Users/benworthington instead.

I'd be grateful if you could let me know what I'm doing wrong.

Many thanks

Ben

RobTrew 2009-08-24 02:08 AM

[quote]My Dropbox folder resides in my home folder ie Users/benworthington/Dropbox.[/quote]

home folder = user folder

[CODE]property strDocsPath : (path to home folder as text) & "Dropbox"[/CODE]

[COLOR="White"]--[/COLOR]

rossonr 2009-10-08 10:42 AM

Finally sat down and integrated the scripts for OF and DTPO. After getting all projects into DT with the scripts I have gone though and removed my notes from the projects. Lucky for me DTPO and OF sit side by side on the same space so referencing is super simple.

Only question I have is when a project or task is complete what steps are taken to keep all in sync. Currently it looks to me once a task/project is complete the user will need to visit both Applications to mark them as so.

If I am mistaken please let me know how this will be accomplished.

TIA

RobTrew 2009-10-08 01:36 PM

[QUOTE=rossonr;68041]Currently it looks to me once a task/project is complete the user will need to visit both Applications to mark them as so.[/QUOTE]

You are right, though it would certainly be possible to add a further script which marked the selected OF project as completed, and set the label of the corresponding DT folder to 'Done'.

rossonr 2009-10-09 09:01 AM

[QUOTE=RobTrew;68047]You are right, though it would certainly be possible to add a further script which marked the selected OF project as completed, and set the label of the corresponding DT folder to 'Done'.[/QUOTE]

I vote for it. :) but I applescript hates me :(

rossonr 2009-10-14 04:59 AM

Found another snag in the workflow. One of my projects is set up as single tasks. I have noticed that since all my notes are save in the oo3 file when I go to add a new task to OF under this project and run the script to get the updated version into DevonThink it creates a new file only based on what I have in OF. By it doing this I have no notes. At the moment the only work around I see is to do double entry by adding the item to OF then adding it to Devonthink so I can have my notes for my other tasks.

Is there any plans to have it append?

TIA

RobTrew 2009-10-14 08:29 AM

[QUOTE=rossonr;68280]Is there any plans to have it append[/QUOTE]

For continuously changing project notes I use the OpenProjNotes script, maintaining my working notes in an OO3 file which is in Devon but accessible through the script from OF.

I don't plan to make SaveToDevonAsOO3 append, as that does not correspond to the way I am using it ...

rossonr 2009-10-14 08:48 AM

[QUOTE=RobTrew;68292]For continuously changing project notes I use the OpenProjNotes script, maintaining my working notes in an OO3 file which is in Devon but accessible through the script from OF.

I don't plan to make SaveToDevonAsOO3 append, as that does not correspond to the way I am using it ...[/QUOTE]

Hmm. thought I understood the notes portion. Please correct me if I am wrong here but I should have a <project name>.oo3 file for each project and a <task name> notes.oo3 file for each task that has notes for it.

If that is the case then I might be having an issue with the notes script because it is making a file named <project name> notes.oo3

Again thank you for the scripts and providing more insight to your workflow.

RobTrew 2009-11-11 11:01 PM

[QUOTE=rossonr;68293]it is making a file named <project name> notes.oo3[/QUOTE]

Yes - that is by design.

rmathes 2009-12-01 06:14 PM

Is there a script for taking an item in DevonThink Pro (Office, in my case) and converting it to an action item in OmniFocus?

RobTrew 2009-12-01 10:34 PM

[QUOTE=rmathes;70383]Is there a script for taking an item in DevonThink Pro ... and converting it to an action item in OmniFocus?[/QUOTE]

I haven't written one myself. It could certainly be done.

In the meanwhile, Devonthink's [B]Edit > Copy Item Link[/B] does, of course, allow you to paste a link into an OF notes field.

EDIT:
I notice that there is a script (I haven't tested it) at:
[URL="http://evensongkcni.spaces.live.com/blog/cns!A1FF1D0DDDEA5D2A!105.entry"]http://evensongkcni.spaces.live.com/blog/cns!A1FF1D0DDDEA5D2A!105.entry[/URL]

rmathes 2009-12-02 03:08 AM

Hi Rob. Thanks.....um.....i think. Just trying to read that post about the script made my head hurt. I’m guessing that’s a translated page from some other language.

But if I'm reading this right, it’s not what I'm looking for. This is what he says it does:

“So I maked this Automater Service ( plants on Panthera uncia, not sure about anything before ) to catch the attachments from an e-mail and make new records in the DEVONthink Inbox. “

My ideal here (and it’s not a huge deal because I don’t do this often and when I do I use the edit/copy item link option) would be to highlight an item in DTPO, run the script and have it do for that DTPO item what the Mail Clip o Tron does for emails, create a new action and put the item link into the notes. Doesn’t look like this script does that unless I'm reading this wrong (which is a definite possibility).

RobTrew 2009-12-02 07:03 PM

[QUOTE=rmathes;70395]if I'm reading this right, it’s not what I'm looking for.[/QUOTE]

It's easy to miss - look at [URL="http://dl.getdropbox.com/u/49219/Create%20OF%20Task.scpt"]the link[/URL] to task.scpt near the end of the paragraph which starts: "In run through that procedure ..."

rmathes 2009-12-03 02:56 PM

thank you sir.

Just downloaded it, put it into the application support/DTPO2/Scripts folder, updated the scripts menu and it shows up, select an item and run it, nothing happens. Quit DTPO and relaunched, no change.

Either the script is bad or I'm doing something wrong or it needs editing. Whichever, for now I'll just settle for the copy item link method.

But I appreciate the heads up, thanks again.

dwbrown77 2010-07-08 12:18 PM

Hello, could these scripts be used to link address book contacts with omnifocus. Specifially I would like to be able to be in address book and identify todos that are associated with that individual.

RobTrew 2010-07-08 12:37 PM

[QUOTE=dwbrown77;79843]Hello, could these scripts be used to link address book contacts with omnifocus. Specifially I would like to be able to be in address book and identify todos that are associated with that individual.[/QUOTE]

I haven't looked into an interface with the address book (These scripts interface with Devonthink, and will not, I think, be what you are after).

Xeijin 2010-07-09 07:33 AM

Hi Rob,

Firstly, thanks for the great scripts. In combination with the "Create OF Task" script from judismith of unofficialtechnology I have complete control over my workflow.

One thing which is a minor niggle more than anything else is the following error I'm getting when invoking the [b]OpenProjNotesInDevon[/b] Script:

[CODE]
AppleScript reported the following error:
Finder got an error: Can’t get alias "Macintosh HD:Users:Hassan:Library:Application Support:OmniOutliner 3:Templates:Default.oo3template".
[/CODE]

For now I am working around it by simply opening the project folder using your other script, then manually double clicking on the note file I have stored in DT. I'm pretty sure there is nothing interfering with the process as this is a completely fresh install of SL (just done a few hours ago) and these were the first to applications I installed.

I've done some investigation and there does not seem to exist a "Templates" folder at the path the script specifies, though I'm not sure what template to add there if I need to at all.

I also see someone had a similar error earlier, were you able to replicate it?

Thanks again.

RobTrew 2010-07-09 08:35 AM

[QUOTE=Xeijin;79862]
[CODE]
AppleScript reported the following error:
Finder got an error: Can’t get alias "Macintosh HD:Users:Hassan:Library:Application Support:OmniOutliner 3:Templates:Default.oo3template".
[/CODE]
I've done some investigation and there does not seem to exist a "Templates" folder at the path the script specifies, though I'm not sure what template to add there if I need to at all.[/QUOTE]

By default there will normally be a file named Default.oo3template at that location, but of course it can be deleted.

The advantage of having one is that you can choose the default layout and formatting etc of the notes created with the script.

To get it working. Choose/create a blank OO3 file which on you would like your note files to be based, and use OO3's [B]File > Save As Template ...[/B] to save it to

[CODE]HD:Users:Hassan:Library:Application Support:OmniOutliner 3:Templates:Default.oo3template[/CODE]

(or the equivalent path from the user directory on your system)

Xeijin 2010-07-12 04:56 AM

[QUOTE=RobTrew;79864]By default there will normally be a file named Default.oo3template at that location, but of course it can be deleted.

The advantage of having one is that you can choose the default layout and formatting etc of the notes created with the script.

To get it working. Choose/create a blank OO3 file which on you would like your note files to be based, and use OO3's [B]File > Save As Template ...[/B] to save it to

[CODE]HD:Users:Hassan:Library:Application Support:OmniOutliner 3:Templates:Default.oo3template[/CODE]

(or the equivalent path from the user directory on your system)[/QUOTE]

Hi Rob,

Thanks for the advice. I have saved the template to the templates folder now upon clicking "OpenProjNotesInDevon" OmniOutliner opens and I receive the following error:

[CODE]
The document “Untitled 2” could not be saved as “• Recipes to Try notes.oo3”. The file doesn’t exist.
[/CODE]

and OmniFocus then shows the following error:

[CODE]
AppleScript reported the following error:
OmniOutliner Professional got an error: Couldn't save document. Check that the specified save location is writable and has sufficient space available.
[/CODE]

RobTrew 2010-07-12 05:18 AM

[CODE]
The document “Untitled 2” could not be saved as “• Recipes to Try notes.oo3”. The file doesn’t exist.
[/CODE]

Well, these scripts are, alas, posted "as is" (as draft examples for others to adapt) and only work (if at all) on the assumption of default oo3 settings and default system settings.

It sounds as if there may be a permissions issue on your system with writing to the temporary folder.

All I can really suggest is that you experiment with changing the third line of code which specifies where a temporary copy of the 003 file is saved before it is imported into Devonthink. Try to specify a folder to which you do have full read/write permissions.

[CODE]property strTempFolder : (path to temporary items folder as string)[/CODE]

Good luck !

Xeijin 2010-07-12 07:06 AM

[QUOTE=RobTrew;80006][CODE]
The document “Untitled 2” could not be saved as “• Recipes to Try notes.oo3”. The file doesn’t exist.
[/CODE]

Well, these scripts are, alas, posted "as is" (as draft examples for others to adapt) and only work (if at all) on the assumption of default oo3 settings and default system settings.

It sounds as if there may be a permissions issue on your system with writing to the temporary folder.

All I can really suggest is that you experiment with changing the third line of code which specifies where a temporary copy of the 003 file is saved before it is imported into Devonthink. Try to specify a folder to which you do have full read/write permissions.

[CODE]property strTempFolder : (path to temporary items folder as string)[/CODE]

Good luck ![/QUOTE]

No problem Rob, as I say opening the Project Folder is a more than acceptable workaround for me. I will give this a try when I get a chance. Thanks again.

geggyta516 2010-11-29 11:15 AM

[QUOTE=RobTrew;65033]Should be no problem - you will just need to experiment with adjusting the path strings.

[COLOR="White"]--[/COLOR][/QUOTE]

Does anyone know how paths to groups within a devonthink database are entered into these scripts?

THanks!

RobTrew 2010-11-29 11:34 AM

[QUOTE=geggyta516;89608]Does anyone know how paths to groups within a devonthink database are entered into these scripts?

THanks![/QUOTE]

A dropbox issue ?

(A bit of context might help to clarify what it is that you need to know).

--

geggyta516 2010-11-29 12:10 PM

[QUOTE=RobTrew;89609]A dropbox issue ?

(A bit of context might help to clarify what it is that you need to know).

--[/QUOTE]

Sorry. No. Not Dropbox but want to use the script to create group folders in my sync group of the devonthink database I am using. The script put the new folder in the root of the devonthink database, I want to be able to go further into the sync group.

Thanks!

RobTrew 2010-11-29 12:23 PM

[CODE]tell application "DEVONthink Pro"
tell database 1 -- or whichever database it happens to be
set groupSync to first record where name is "Sync"
end tell
end tell[/CODE]

geggyta516 2010-11-29 12:42 PM

[QUOTE=RobTrew;89612][CODE]tell application "DEVONthink Pro"
tell database 1 -- or whichever database it happens to be
set groupSync to first record where name is "Sync"
end tell
end tell[/CODE][/QUOTE]

Thanks Rob!

RobTrew 2010-11-29 02:16 PM

FWIW there is an even simpler and more direct idiom:

[CODE]tell application id "com.devon-technologies.thinkpro2"
tell database 1 -- or whichever database it happens to be
set groupSync to sync group
end tell
end tell
[/CODE]

larrykkchan 2010-12-03 12:43 AM

The OpenProjNotesInDevon script doesn't work for me. When it come to launch the OO3, it showed the following error message and stopped, please help
Both OF, OO3 and DevonThink Office Pro are the latest version[IMG]http://larry.fifthfloor.org/oo3.png[/IMG]

RobTrew 2010-12-03 06:28 AM

I've seen that once, but it didn't recur on my system - possibly some kind of timing issue.

The script does two things:[LIST][*]Tries to save the OO3 file in a temporary folder[*]Then imports it from the temporary file into DT2[/LIST]
The location of the temporary folder which it tries to use is determined by the line near the start of the script:
[CODE]property strTempFolder : (path to temporary items folder as string)[/CODE]

It may be that Applescript sometimes hasn't retrieved a reference to the temporary items folder in time, or conceivably that there are permissions problems in writing to it.

I would begin by editing the line above to
[CODE]property strTempFolder : (path to documents folder as string)[/CODE]

and then seeing if the problem persists.

larrykkchan 2010-12-03 05:40 PM

[QUOTE=RobTrew;89868]I've seen that once, but it didn't recur on my system - possibly some kind of timing issue.

The script does two things:[LIST][*]Tries to save the OO3 file in a temporary folder[*]Then imports it from the temporary file into DT2[/LIST]
The location of the temporary folder which it tries to use is determined by the line near the start of the script:
[CODE]property strTempFolder : (path to temporary items folder as string)[/CODE]

It may be that Applescript sometimes hasn't retrieved a reference to the temporary items folder in time, or conceivably that there are permissions problems in writing to it.

I would begin by editing the line above to
[CODE]property strTempFolder : (path to documents folder as string)[/CODE]

and then seeing if the problem persists.[/QUOTE]

It works fine now! Thanks a lot for your great work!!

lamp 2011-04-17 02:38 PM

Hi Rob -- The scripts works brilliantly! I have a request to change the mapping between OF and Devonthink folders. Not sure if this has been addressed before.

Right now the script "OpenProjFolderinDevon" when both my OF and Devonthink has exactly the same file hierarchy name.

Let's say I have 2 roles with my company, Right now On OmniFocus I have:
OF Library
- Work Role 1 Folder (under OF Library "root" folder)
--> Project 1
- Work Role 2 Folder
--> Project 1

And this directly reflects my Devonthink DB Folders:
- Work Role 1 Folder
--> Project 1 Folder

What I want is to simplify the "Folders" in OF into just "Work Folder", "Personal Folder" and "Someday / Maybe Folder". The reason is I have too many Work related "Folders" under the "root" Library folders, and my Personal folders are just buried...

What I'd like is this:
OF Library
- Work Folder
-- Work Role 1 Sub-Folder
---> Project 1
-- Work Role 2 Sub-Folder
---> Project 1
- Personal Folder
- Someday / Maybe Folder

And keeps the Devonthink DB Folder the same.

In other words, I want to map OF Library/Work Folder/Work Role 1 subfolder with Devonthink "Work Role 1 Folder.

Right now in OF if I move the "Work Role 1 Folder" under the newly created "Work Folder", the script will create a new Devonthink "Work Folder Folder" - "Work Role 1 Folder" -- "Project 1 Folder".

I look at the script and it seems that GetOFProjPath always get the Full path of the OF project. What should I change to achieve this?

Thanks in advance for suggestions!
/Peter

RobTrew 2011-04-28 06:34 PM

The path string returned by GetOFProjPath() is easily chopped up.
You can extract the sub-path that you want with code along the lines of:

[CODE]
-- make a copy of the existing text item delimiter (to be restored later)
set strDelim to my text item delimiters

-- Change the text item delimiter to allow segmentation of the full path
set my text item delimiters to "/"

-- Get a list of the path segments
set lstSegments to text items of GetOFProjPath()

-- Extract some sub-section of the full path, e.g.
set strLastTwo to (items -2 thru -1 of lstSegments) as string

-- restore the original text item delimiter
set my text item delimiters to strDelim[/CODE]

peterlemer 2011-05-12 12:04 PM

sorry to be so late to catch up on this, but when I want to export from OF to DevonThink, I want the action header and contents to be copied so I can delete the OF original.

I am trying to remove all non-project-specific information so finding an entry in DT that is merely a link back to OF isn;t what I need.

Any idea how I can tame this script?

cheers

pete

RobTrew 2011-05-12 10:12 PM

I plan to revisit this script fairly soon to make it less dependent on maintaining parallel hierarchies (perhaps by storing the UUID for a DevonThink folder in the note field of a project).

The idea is to be able to make changes in OmniFocus (folder hierarchies, position of particular projects within these hierarchies) without losing the link between an OF project and a DT folder.

Its possible that the new script may also be more helpful for your particular work-flow.

(Very happy to share scripts that I write to meet my own needs, and it might well be diverting to offer a customization service, but the days, alas, are short, and of uncertain number :-)

tunesmith 2011-05-23 04:40 PM

I am having trouble figuring out why the oo3 scripts aren't working for me. I have OO Pro and DT Pro. In trying to debug, I run OpenProjNotesInDevon from apple script editor. I get an error:

error "Can’t set URL of missing value to \"omnifocus:///task/aAO6PyXE1u4\"." number -10006 from URL of missing value

and the line that is highlighted is:


set URL of oMovedRec to strURL

The same thing happens if I try setting strTempPath to my documents folder, too.

I get a different problem with the other oo3 script - it creates an oo3 document, but puts it in my global inbox, not in my hierarchy. When I run it from the editor, the script stays running for a very long time - eventually AppleScriptEditor stops responding and I have to force-quit it.

The openProjectFolder script works fine.

RobTrew 2011-05-23 11:42 PM

This looks like the same issue as that discussed around post 53 above.

I will be revisiting these scripts in about two weeks, once a seasonal peak of work has subsided ...

In the meanwhile, what is your hardware and software platform ? My first impression is that this is a timing issue ...

tunesmith 2011-05-24 06:09 PM

[QUOTE]In the meanwhile, what is your hardware and software platform ? My first impression is that this is a timing issue ...[/QUOTE]

Latest of everything - macbook pro 15", 10.6.7 . Thanks!!

RobTrew 2011-06-19 02:00 PM

I have posted first drafts of a rewrite of two OmniFocus-DevonThink integration scripts at [URL="http://bit.ly/OFOC-Devon"]http://bit.ly/OFOC-Devon[/URL] (See - Experimental version 2)
[LIST][*][I]Open oo3 project notes in DevonThink for the selected OF project[*]Open a DevonThink folder for the selected OF project[/I][/LIST]
These early drafts mainly aim to allow for more flexibility, doing away with the need to maintain parallel folder structures in DevonThink and OmniFocus.

[SIZE="1"](They achieve this by storing hyperlinks, in the OF project note field, to folders and oo3 documents in a DT database. When folders and oo3 notes documents are first created, they are, as before, initially given a DT folder path which matches the project folder path in OmniFocus. The use of DT hyperlinks means, however, that subsequent rearrangements of folder nesting, whether in DT or OF or both, will not break the link between the OF projects and the corresponding materials in DT).[/SIZE]

Another goal of the redrafts is to address some reports of error messages arising when the "open project notes" script is finding or creating its oo3 notes.

[SIZE="1"](Using hyperlinks should improve the reliability of finding the notes, which no longer depends on file-paths remaining static within the DT database. In addition the mechanism used for creating a fresh oo3 note file has changed. Fresh note files are no longer copied from an .oo3template file in ~/Library/Application Support/OmniOutliner 3/Templates.

Instead, the script tries to copy the new note file from a document called Default.oo3 in the same folder as the script. If no such file is found, the new oo3 file is based on a Default.oo3 inside the script bundle.

Users who wish their notes files to have particular fonts and layout should, therefore, prepare a blank sample, and save it as Default.oo3 to the folder in which the script is stored).[/SIZE]

As this is an early draft, there will be bugs, and anyone choosing to experiment with these scripts should[B] back their data up[/B]. Bug reports will be welcome, and should be sent to houthakker72 at gmail.com

[COLOR="White"]--[/COLOR]

RobTrew 2011-06-26 10:45 PM

I've updated the Save2DevnAs003 (OmniFocus to DT2) script to fix an issue which, on some systems, could lead to error messages relating to the oo3 file.

[URL="http://bit.ly/OFOC-Devon"]http://bit.ly/OFOC-Devon[/URL]

[I plan, at some point this boreal summer, to edit this (and the Save2DevnAsTXT script) so that they find/create links to DT2 project folders, and are no longer dependent on maintaining parallel folder structures in OF and DT.

If this seems useful, and I don't appear to have done it, you can try reminding me at houthakker72, which is a gmail address]

RobTrew 2011-09-10 02:37 PM

I have added a simple utility script to [URL="http://bit.ly/OFOC-Devon"]this collection[/URL].

[B]SetDBforOmniFocusFolder[/B] allows you to choose which DEVONthink database will be used for the selected OmniFocus folder. The default is “OmniFocus Notes”, but this script will offer you a list of the databases currently open in DT, and will store the path of the database you choose in the invisible note field of the selected OF Folder.

The [I]OpenProjFolderinDevon[/I] and [I]OpenProjNotesinDevon[/I] scripts will then use the specified database for all projects enclosed by that folder and its child folders. (Except where any of these have been given their own database assignment by this script).

Paul_A 2012-02-01 04:24 AM

Hi Rob,
I'm very new to DevonThink, Omnifocus, and scripting, so this I may be missing something absolutely obvious.
I've installed all 5 scripts in the tool bar of omnifocus. I get the Save2Devn and OpenProj ... scripts to work as advertised (except on first run it seems to think that YOU are still a user on my machine. This cleared up after opening AppleScript editor and resaving the scripts).

However, nothing happens at all when I try to run the SetDBforOmniFocusFolder script. I was under the impression I should see a menu somewhere, but no joy.

I'm running all of this on os x 10.7.2 (lion) on a 2011 macbook air.

Thanks for any help ..
Kind Regards

Paul

RobTrew 2012-02-01 05:01 AM

[QUOTE=Paul_A;106817]This cleared up after opening AppleScript editor and resaving the scripts[/QUOTE]

Thanks for that report - sounds like I need to distribute in uncompiled text form.

[QUOTE=Paul_A;106817]However, nothing happens at all when I try to run the SetDBforOmniFocusFolder script. I was under the impression I should see a menu somewhere[/QUOTE]

Are you selecting a folder in OF before you run it ?
(It won't do anything if no folder is selected)

dimitrilw 2012-11-19 04:08 AM

link to storage?
 
RobTrew--- The link you were using to share the scripts is no longer valid as mobileme has been decommissioned. Are you still sharing the scripts at a new location? If not, perhaps a dropbox.com publicly-accessible folder? I would really like to get my hands on the scripts; they sound like a complete fit for what I'm looking for. ---Cheers, Dimitri

whpalmer4 2012-11-19 07:35 AM

[url]http://www.complexpoint.macmate.me/Site/OmniFocus_%26_DEVONthink.html[/url]

RobTrew 2012-11-19 09:46 AM

Thanks for giving the link. I've been through the earlier posts in the thread and generally reset them to [URL="http://bit.ly/OFOC-Devon"]this shortcut[/URL].

dimitrilw 2012-11-20 01:58 AM

ty
 
Thank you!

docsbo 2014-01-14 06:32 AM

Scripts location
 
Warming up an old thread...

...reinstalling all my old stuff and I don't have a backup of the scripts:

[COLOR="Blue"]-> RobTrew - where can I find the scripts now ? the bit.ly gives a 404 error...
[/COLOR]

Regards Stan

sven.luetkemeier 2014-01-23 12:08 PM

You can find Rob Trew's Script at

[url]https://github.com/RobTrew/tree-tools/blob/master/DevonThink%20scripts/IntegratingDEVONthink2-OmniFocus1.md[/url]

docsbo 2014-01-23 12:25 PM

Thanks Sven !

TheWart 2014-05-09 07:09 AM

Help editing for plain text use
 
I am a big fan of Rob's scripts, and they have made many things simpler for my workflow. I need a little bit of help on one of them.

The OF/DTPO Project Notes in OO3 works very well on my Mavericks system. However, I would like to use plain text. I am not able to upgrade OO3 to OO4 to fix the lack of Quick Look of .oo3and which therefore makes DTTG useless to view the linked project plans.

The script includes an option for FoldingText, but I would like to use TextMate 1. Is this something I could change easily?

I have attempted to modify the script to allow TextMate. On the code below I get "Error Number:Can't get <<class rURL>> of missing value. -1728"

Any help would be appreciated!

[CODE]property pblnJustFolder : false
property pblnUseSyncAsRoot : false
property pblnPreferFTToOmniOO3 : true

-- Robin Trew

-- ver .204 June 19 2011
-- ver .205 [corrects a bug in which a newly created folder was not immediately displayed]
-- ver .206 [unifies the folder and notes scripts, differing only by value of
-- the property pblnJustFolder at the top of the script]
-- Aug 22 2011
-- Ver .208 Still defaults to the DT Database named in pstrDTDB (below)
-- but can use different DT databases for different OF folders
-- (will use the first existing DT database whose POSIX path is found in the note of an enclosing OmniFocus folder
-- [a script for editing OF folder notes can be found at
-- http://forums.omnigroup.com/showthread.php?t=21942]
-- ver .211 Sep 12 2011
-- Adds option, above - top of script, to make the Sync group the root of all new folders
-- Ver .214 Nov 19 2012 Uses www.FoldingText.com rather than OO3 if pblnPreferFTToOmniOO3=true

-- Disclaimer
-- This is just a rough draft of something which I have sketched for my own personal use,
-- and which is provided purely as an illustration of possible approaches to coding.
-- You are free to adapt and reuse any part of it, without any warranties, implied
-- or explicit, as to its behaviour or suitability for use

-- IF property pblnJustFolder : **false** (see top of script)
-- CREATES/OPENS A PROJECT NOTES FILE (STORED IN DEVONthink 2) FOR THE SELECTED OMNIFOCUS PROJECT.
-- 1. The project notes file is an OmniOutliner 3 document stored in DEVONthink 2 folder
-- 2. The Devonthink record contains a hyperlink back to the OmniFocus project
-- 2. The script ensures that a DT hyperlink to the document in DevonThink is placed in the note field of the project
-- 3. In the absence of a link to existing notes in DevonThink,
-- the script will seek or create the 003 file in a DevonThink folder which matches
-- the folder path of the project in OmniFocus
-- (and add the hyperlinks from project to notes, and from folder and notes to project)

-- OR - IF property pblnJustFolder : **true** (see top of script)
-- JUST CREATES/OPENS A PROJECT MATERIALS FOLDER (IN DEVONthink 2)
-- FOR THE SELECTED OMNIFOCUS PROJECT.
-- 1. The script ensures that a DT hyperlink to the document in DevonThink is placed in
-- the note field of the project
-- 2. In the absence of a link to an existing folder in DevonThink,
-- the script will add the hyperlinks from project to folder, and from folder to project)


-- Acknowledgements
-- Inspired by Jim Harrison's excellent scripts, which use the Finder rather than DEVONthink 2
-- http://jhh.med.virginia.edu/main/OmniFocusScripts
-- The icon attached to this file is from the Float collection by Corey Marion
-- http://iconfactory.com/freeware/preview/flot

-- GLOBAL CONSTANTS
-- Initially assumes that project folders will be maintained in
-- a database named [UserName]/Documents/Omnifocus Notes.
-- Edit the name and path below to change the location and/or name
--of the main Projects folder that will contain the individual project folders

property pstrDTDB : "Projects" -- name of default Devonthink Database
property pstrDTsuffix : ".dtBase2"
property pstrDocsPath : (path to documents folder as string) -- path to ~/Documents
property pstrSync : "/Sync"

property pstrTemplate : "Default"
property pstrOO3Suffix : ".oo3"
property pstrFTSuffix : ".txt"

property pstrOFPrefix : "omnifocus:///task/"
property pstrXMLPrefix : "<value key=\"link\">"
property pstrRunDelim : "</lit></run>"
property pstrDTPrefix : "x-devonthink-item://"
property pstrDBPath : "~/Library/Caches/com.omnigroup.OmniFocus/OmniFocusDatabase2"
property pstrFolderLinkTitle : "[Devonthink support folder for this project]"
property pstrNoteLinkTitle : "[Devonthink project plans]"
property plngURLchars : 36

on run


-- IS A PROJECT (OR ONE OF ITS TASKS) SELECTED IN OMNIFOCUS ?
set {oProject, strProjName, strProjID} to GetSeldProject()
if oProject is missing value then return

-- IS THERE A RELEVANT LINK IN THE NOTE FIELD OF THE PROJECT ?
set {strFolderURL, strNotesURL} to DTLinksInNote(oProject)

-- AND IF SO, DOES IT LEAD ANYWHERE ?
if pblnJustFolder then
if strFolderURL ≠ "" then if FollowDTLink(strFolderURL) then return
else
if strNotesURL ≠ "" then if FollowDTLink(strNotesURL) then return
end if

-- IN THE ABSENCE OF A LIVE DT LINK, CREATE OR FIND A MATCHING FOLDER PATH IN DT
tell application id "DNtp"
set oDTFolder to my GetParallelFolder(oProject)
if pblnJustFolder then
set strDTLink to reference URL of oDTFolder
else
-- WHICH NOTE APP ARE WE USING - TEXTMATE OR OO3 ?
set blnFT to pblnPreferFTToOmniOO3 and my isAppInstalled("com.macromates.textmate")
if blnFT then
set strNoteSuffix to pstrFTSuffix
else
set strNoteSuffix to pstrOO3Suffix
end if

-- CREATE OR FIND A NOTE FILE FOR THIS PROJECT
set strNoteName to "• " & strProjName & " notes" & strNoteSuffix
set recNotes to my GetNotes(oDTFolder, strNoteName, strNoteSuffix, strProjID, blnFT)
set strDTLink to reference URL of recNotes
end if
end tell

-- PLACE AN RTF-FORMATTED DT LINK TO THE NEW OR PRE-EXISTING NOTES IN THE NOTES FIELD OF THE PROJECT
if pblnJustFolder then
set strLinkTitle to pstrFolderLinkTitle
else
set strLinkTitle to pstrNoteLinkTitle
end if
my PasteToNote(oProject, strLinkTitle, strDTLink)

-- AND FOLLOW THE LINK TO THE FOLDER OR NOTES DOCUMENT IN DT2
FollowDTLink(strDTLink)
tell application id "DNtp" to activate
end run

-- Check whether an app is installed e.g. isAppInstalled("com.foldingtext.FoldingText")
-- for http://www.foldingtext.com
on isAppInstalled(strBundleCode)
try
tell application "Finder"
name of (application file id strBundleCode) ≠ ""
end tell
on error
return false
end try
end isAppInstalled

-- Return the first project selected in the Omnifocus GUI
on GetSeldProject()
tell application id "OFOC"
tell front document
-- GET THE FIRST SELECTED PROJECT (CONTENT OR SIDEBAR)
if (count of document windows) < 1 then return {missing value, "", ""}
tell front document window
set oProject to missing value
repeat with oPanel in {content, sidebar}
set lstSelns to (value of selected trees of oPanel where (class of value = task) or (class of value = project))
if (count of lstSelns) > 0 then
set oProject to first item of lstSelns
exit repeat
end if
end repeat
if oProject is missing value then return {missing value, "", ""}
if class of oProject = task then set oProject to containing project of oProject
tell oProject to return {it, name, id}
end tell
end tell
end tell
end GetSeldProject

on DTLinksInNote(oProject)
tell application id "OFOC"
-- DOES ITS NOTE CONTAIN A DEVONTHINK URL ?
set strQuery to "select CAST(notexmldata as text) from task where persistentIdentifier = \"" & (id of oProject) & "\""
set strNoteXML to do shell script "sqlite3 " & pstrDBPath & space & quoted form of strQuery
set strLink to pstrXMLPrefix & pstrDTPrefix
set blnOpened to false
if strNoteXML contains strLink then
set {strDlm, my text item delimiters} to {my text item delimiters, pstrRunDelim}
set lstRuns to text items of strNoteXML
set my text item delimiters to "<lit>"
set {blnFolder, blnNote} to {false, false}
set {strFolderURL, strNotesURL} to {"", ""}

set strStart to rich text 1 thru 2 of pstrNoteLinkTitle
repeat with oRun in lstRuns
set lstSections to text items of oRun
if length of lstSections > 1 then
set strLabel to item -1 of lstSections
set strPreamble to item -2 of lstSections

if strLabel begins with strStart then
if not blnFolder then
if strLabel contains "folder" then
set strFolderURL to my ParseLink(strPreamble)
if strFolderURL ≠ "" then set blnFolder to true
end if
end if
if not blnNote then
if strLabel contains "notes" then
set strNotesURL to my ParseLink(strPreamble)
if strNotesURL ≠ "" then set blnNotes to true
end if
end if
end if
if blnFolder and blnNote then exit repeat
end if
end repeat

set my text item delimiters to strDlm
return {strFolderURL, strNotesURL}
else
if note of oProject = "" then set note of oProject to space -- (seems to prepare note for easier opening later)
return {"", ""}
end if
end tell
end DTLinksInNote

on ParseLink(strXML)
set {strDlm, my text item delimiters} to {my text item delimiters, pstrXMLPrefix & pstrDTPrefix}
set lstParts to text items of strXML
set strURL to ""
if length of lstParts > 1 then
set my text item delimiters to "</value>"
set strURL to first text item of item 2 of lstParts
if length of strURL = plngURLchars then
set strURL to pstrDTPrefix & strURL
else
set strURL to ""
end if
end if
set my text item delimiters to strDlm
return strURL
end ParseLink

on FollowDTLink(strURL)
if strURL ≠ "" then
set blnOpened to (do shell script "open " & quoted form of strURL) = ""
if blnOpened then
tell application id "DNtp" to activate
return true
else
return false
end if
else
return false
end if
end FollowDTLink


on GetParallelFolder(oProject)
set {strPath, strFolderDB, strProject} to GetProjPath(oProject)
tell application id "DNtp"

-- CHOOSE THE TARGET DATABASE
-- EITHER FROM A PATH IN THE ENCLOSING FOLDER, OR FROM THE DEFAULT
if strFolderDB ≠ "" then
set strDb to strFolderDB
else
set strDb to (POSIX path of pstrDocsPath) & pstrDTDB & pstrDTsuffix
end if

set oDb to open database strDb
if oDb is missing value then
set oAnswer to display dialog "Create new Devonthink database at \"" & strDb & "\" ?" buttons {"Cancel", "OK"} default button 1
if the button returned of oAnswer is "Cancel" then return
set oDb to create database strDb
end if

-- DEPENDING ON GLOBAL SETTING, OPTIONALLY CREATE NEW FOLDER WITHIN SYNC GROUP
if pblnUseSyncAsRoot then
set oLocn to create location pstrSync & strPath in oDb
else
set oLocn to create location strPath in oDb
end if
set URL of oLocn to pstrOFPrefix & (id of oProject)
return oLocn
end tell
end GetParallelFolder

on GetProjPath(oProject)
tell application id "OFOC"
set strProject to name of oProject
set strPath to strProject
set oContainer to container of oProject

set blnFolderFound to false
set strFolderDB to ""

set cClass to the class of oContainer
repeat while cClass is not document
if not blnFolderFound then
if cClass is folder then
set strFolderDB to note of oContainer
if ((strFolderDB ends with pstrDTsuffix) and my FileExists(strFolderDB)) then set blnFolderFound to true
end if
end if
set strPath to name of oContainer & "/" & strPath
set oContainer to container of oContainer
set cClass to the class of oContainer
end repeat
return {"/" & strPath, strFolderDB, strProject}
end tell
end GetProjPath

on GetNotes(oDTFolder, strNoteFile, strNoteSuffix, strProjectID)
tell application id "DNtp"
set lstNoteRecs to children of oDTFolder where name = strNoteFile
if length of lstNoteRecs > 0 then
return first item of lstNoteRecs
else
-- IMPORT A FRESH TEMPLATE FILE FROM THE SAME FOLDER AS THIS SCRIPT
set strScriptFolder to POSIX path of (path to me)
--tell application id "MACS" to set oScriptFolder to container of oThisScript

set strTemplate to strScriptFolder & pstrTemplate & strNoteSuffix
if my BundleExists(strTemplate) or my FileExists(strTemplate) then
set oRec to import strTemplate to oDTFolder
else
-- OR FROM INSIDE THE SCRIPT BUNDLE
set strTemplate to POSIX path of (path to me) & pstrTemplate & strNoteSuffix
try
set oRec to import strTemplate to oDTFolder
on error
display alert strTemplate & " not found in this script bundle"
return missing value
end try
end if

tell oRec
if it is missing value then return it
set its name to strNoteFile
set its URL to pstrOFPrefix & strProjectID
end tell
return oRec
end if
end tell
end GetNotes

on FileExists(strPath)
(do shell script ("test -e " & quoted form of strPath & "; echo $?")) = "0"
end FileExists

on BundleExists(strPath)
(do shell script ("test -d " & quoted form of strPath & "; echo $?")) = "0"
end BundleExists

on PasteToNote(oObj, strLegend, strURL)
set strHTML to quoted form of ("<font face=\"Helvetica\"><a href=\"" & strURL & "\">" & strLegend & "</a></font><p>")
do shell script "echo " & strHTML & " | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf"
tell application id "OFOC"
tell default document
set lngWins to count of document windows
if lngWins < 1 then make new document window
set visible of front document window to true
set oWin to front document window
set cClass to class of oObj
if not (cClass is in {task, inbox task, project}) then return
tell oWin
if selected view mode identifier ≠ "project" then set selected view mode identifier to "project"
if cClass is inbox task then
tell tree 1 of sidebar -- Inbox
if not selected then set selected to true
end tell
else
if (focus as list) ≠ {} then set focus to {}
tell tree 2 of sidebar -- Library
if not selected then set selected to true
end tell
end if
end tell

set strID to (id of oObj) as string -- haven't quite worked out why re-referencing the object
if cClass = inbox task then
set oObj to inbox task id strID -- seems to be necessary here (for selection to work)
else if cClass = task then
set oObj to task id strID
else
set oObj to project id strID
end if
tell content of oWin
select {oObj}
set oSeln to first selected tree
set selected of oSeln to false
set selected of oSeln to true
set note expanded of oSeln to false
end tell
end tell
activate
end tell
tell application id "sevs"
keystroke "'" using {command down} -- second time if needed
keystroke "v" using {command down} -- Paste
-- keystroke "'" using {command down} -- second time if needed
end tell
do shell script "sleep 0.2"
tell application id "OFOC"
tell front document
tell content of front document window
set oSeln to (first selected tree)
set selected of oSeln to false
set note expanded of oSeln to false
set selected of oSeln to true
end tell
end tell
end tell
end PasteToNote
[/CODE]


All times are GMT -8. The time now is 07:18 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.