Scripts run on DT launch and quit?

Sorry if this information is somewhere - I’ve been all over this web site and Google and not been able to find it.

Does DT (I’m running Pro) have some hooks in it somewhere to automatically run an Applescript when the program is launched, and likewise, to run an Applescript when the program quits?

Thanks in advance for any help!

No, but you could write a simple AppleScript that launches DT and then runs the script you want. That handles the at-launch part of your suggestion. The at-quit portion is also possible (in the same script), and you’d need to have your script monitor whether DT is running or not. See MacScripter.net for some advice on doing that.

Thanks, Korm-

I’ve been working on a script that works exactly the way you describe. I was just hoping I could avoid having to deal with separate launcher application.

Thanks again!

Could probably write an automator action (and save it as an app) for this. Or use LaunchBar, QuickKeys, etc.

Just curious, but what actions do you want to execute at the beginning and end of a DEVONthink session – perhaps some reader has solved that particular problem already.

I’ve been keeping my DEVONthink Pro databases in Dropbox, so that I can access them from my laptop and my desktop machine. I know this isn’t recommended, but I figure that as long as only computer at a time has the files open, there shouldn’t be a problem. b[/b]

Back in the Stone Age (dBase II on CP/M) I used to do some freelance database programming, so I’m somewhat familiar with the basic principles of file locking and record locking. I’ve put together an Applescript to implement what I call “application” locking in DEVONthink Pro: if the app’s running on one computer, you can’t run it on the other one.

I’ve written an Applescript (called DTlauncher) that uses a file placed in my Dropbox folder to indicate whether DEVONthink is running on either of my computers. The basic idea is this:

-look for a “lock” file at the top level of Dropbox
-if the “lock” file exists:[list]exit with a warning that DT is already running
-if the “lock” file doesn’t exist:
-launch DEVONthink Pro
-create the “lock” file in Dropbox
-wait in the background until DEVONthink quits
-and then delete the “lock” file[/list:u]

This way, if I wander away from one of my computers and leave DT running, when I try to launch it on the other computer (using this Applescript of course), it will see the “lock” file and warn me that I already have my files open.

Of course, this only works if DEVONthink Pro is launched by this Applescript. If you launch the program itself or double-click on one of its databases, the lock file will never be created. That’s why I was hoping DT had some ability to run scripts at launch and shutdown.

I’ve got the script written, and AFAICT it’s working fine. I’d be happy to share this with other users. I’m not sure what’s the best way to go about that though, so any suggestions would be appreciated. Should I post the code here as an attachment or a text file in a post? Or should I send it to someone [semi-?] official to have them look it over before I share it? I am a fairly experienced amateur programmer, but I have just enough experience with Applescript to know that I hate it thoroughly.

I realize Dropbox isn’t officially supported or recommended by Devon Technologies, so I’m a little more cautious than I would be about posting stuff like this on some other non-corporately-sponsored board. (Don’t want to make enemies with my very first post!)

This should be helpful to users who want to use Dropbox for this purpose. (Full disclosure: I wouldn’t use Dropbox for synchronization. :confused: )

You’d post a message and include your script between “[ code] [/code ]” tags (without the spaces).

Not entirely.

Your script is nice and does solve part of the problem. But this isn’t the whole story. There are rules that must be followed to use Dropbox successfully but the bottom line is that - the database has to be completely synced before opening, as well. Your script insures that the database isn’t open on another coputer (and that helps!) but it can’t guarantee this (I don’t think…). If I have one computer at work and do some work, I can close the database and let Dropbox sync it. But if I go home, turn on my computer and open Dropbox (and the older, local version of the database) before the computer has synced with Dropbox, corruption results.

I’ve been using Dropbox to sync my databases for a long time but I still make mistakes. Even if you remember to close Devonthink on every computer, all it takes is a dropped Internet connection or a laptop that has been off or sleeping for a while. Even if you keep all of your computers on all the time and let Dropbox sync them constantly, mistakes are easy to make.

Tom S.

Tom-

Thank you for taking the time to provide details about the way things can go wrong in using Dropbox. Much appreciated!

Well, I’ve stumbled across some interesting things, and it looks like my Applescript is completely unnecessary!

I had my Dropbox prefs set to “Show desktop notifications” so I’d get messages any time my Dropbox folder was updated. I opened one of the DT databases in my Dropbox, and lo and behold, a message popped up briefly on my other computer:

Screen shot 2011-06-25 at 11.46.08 AM.jpg
I looked in my Dropbox, and didn’t find the file immediately. It turns out the file is inserted inside the “.dtBase2” package. You can see it by opening the database in DT. Then right-click on the database file in the Finder and choose “Show package contents” from the contextual menu:

DEVONthink.lock in show package contents.pngWhen you quit DEVONthink, you’ll see this file disappear again, and if you have Dropbox set to show desktop notifications, you’ll see a message that two files have been updated. (The other one is the Settings.plist file in the same database package.)

Apparently, Devon has already implemented some sort of file-locking. It’s not well-publicized; a Google search for ‘“DEVONthink.lock”’ (with the quotation marks) only turned up 8 hits. But it sounds like anything I would try to do in addition to this would be superfluous.

In light of this - and with the disclaimer that I AM NOT AN EXPERT! - it looks to me like the only real danger of using Dropbox for your DEVONthink Pro databases are the dangers associated with using Dropbox in general, which are mainly opening and closing files (and/or shutting down computers) before Dropbox has had a chance to bring everything into sync.

Thanks to everyone for their comments!

drum365, I don’t think locking the database solves the issue of making certain that it will be updated by download of changes from the cloud via Dropbox, before access to it on the second computer.

That Lock file is automatically added by DEVONthink whenever there is either an attempt to access an open database by a second copy of DEVONthink, or whenever a database isn’t properly closed after access. It’s an attempt to mitigate damage to the database.

Presence of that Lock file will result in display of the ‘in use’ message when DEVONthink next attempts to open the database. Clicking ‘Continue’ to open the database doesn’t guarantee that the download of changes from the cloud is complete.

I’d use Quickeys as it has the ability to run AppleScript and Automator actions and can be set to run on an app event such as an app opening or quitting.

It is not compatible with Lion yet but they are working on that.