Package: pydt3
PyDT3 - The Python API For DEVONthink 3This project aims to let you use Python to interact with DEVONthink 3 with ease.Ulike many other API wrapper projects, PyDT3 is documented through docstring. Therefore can benefit from code completion and documentation in code editors.To install, just runpipinstallpydt3Most of the classes and methods map directly to the AppleScript APIs.For example:frompydt3importDEVONthink3dt3=DEVONthink3()fordbindt3.databases:print(db.name)selected_record=dt3.selected_records[0]print(selected_record.name)tellapplication"DEVONthink 3"repeatwithdbindatabaseslognameofdbasstringendrepeatsetselected_recordtoitem1ofselectedrecordslognameofselected_recordasstringendtellThese two scripts do the same thing.The project is still in early stage. Not all properties and methods have been implemented.InstallationPippipinstallpydt3Quick Startfrompydt3importDEVONthink3dtp3=DEVONthink3()inbox=dtp3.inbox# create a new folder in inboxdtp3.create_location('new-group-from-pydt3',inbox)# get selected recordsrecords=dtp3.selected_records# get the first selected record and print its informationifrecords:first=records[0]print(first.name)print(first.type)print(first.reference_url)print(first.plain_text)# create record in inboxrecord=dtp3.create_record_with({'name':'hello-from-pydt3','type':'markdown','plain text':'# Hello from pydt3',},inbox)RequirementsDEVONthink 3Python 3.7+PyObjC(Seerequirements.txtfor more information.)Work With ChatGPTAdd Tags to Selected Records Using ChatGPTPut thisscriptinto~/Library/Application Scripts/com.devon-technologies.think3/Contextual Menuand run it from contextual menu in DEVONthink (The record must be in selected state).And voilà, the tags are added based on contents automatically.Note: You are required to have anAPI keyfrom OpenAI. The first time you run the script, a prompt will ask you to enter key.The key will be store in Incoming group for DEVONthink (usuallyInbox). You can see the file__openai_api_key__generated there. You can move it to other opened database but don't change it's name.Auto Writing / Summarizing Using ChatGTPThis scriptlets you to insert<<TOKEN>>into your text and then generate the text based on the token.Put the script into~/Library/Application Scripts/com.devon-technologies.think3/Toolbar. Restart the DEVONthink and you will see the script in the toolbar customization window.About the Release ScriptsThe script bundles provided by the project are packed by PyInstaller so that you can run them without Python installation. But the size is relatively large. You can write your own version if you do have Python installed (with required packages.) See codes in examples for more information.RemarksFor those properties that are not implemented, you can still use the through the fallback method. Just that you cannot use the python style naming convention (Basically it will pass the python names directly to JXA).# a.propertyName (int) is not implemented in PyDT3.p=a.propertyName()a.propertyName=(p+1)This project uses PyObjC to execute AppleScript code in Objective-C then wrap them in Python.The bridging part is inspired bypy-applescript.Many of the APIs are generated by ChatGPT from the DEVONthink's AppleScript dictionary.Notes used as examples are imported fromThe Blue Book, a personal wiki shared bylyz-code.LimitationsThe APIs are not fully tested. Please report any issues.Rich texts in AppleScript are converted to strings in Python, which causes style information loss.Now rich text is partially supported.Collections of elements (eg.database.records) are converted to lists in Python. While in Applescript they are retrieved in a lazy manner. This may cause performance issues with large collections.Now they are wrapped in anOSAObjArrayobject and are evaluated lazily.TODOImplement all APIsAbility to execute JXA code snippets.whosefilter forOSAObjArraycontainer.