-
Notifications
You must be signed in to change notification settings - Fork 0
/
TOC generate with btt-links.applescript
32 lines (27 loc) · 1.82 KB
/
TOC generate with btt-links.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
-- Generate a table of contents (TOC) in DEVONthink's Markdown documents.
-- The script also adds Back-to-toc links over each headline.
--
-- This script relies on an external Python script (works for both, Python 2 and 3). The path to the folder, that contains that Python script, must be added to this Applescript (in 'MyPythonScriptPath').
--
-- author: Fabrizio Musacchio (https://www.fabriziomusacchio.com)
-- date: Feb 18, 2022
-- Please specify the path to the folder, where you've saved the Python script:
set MyPythonScriptPath to "<SET PATH TO THE PYTHON SCRIPT FOLDER>"
if MyPythonScriptPath = "<SET PATH TO THE PYTHON SCRIPT FOLDER>" then error "Error: Variable 'MyPythonScriptPath' not set. Please set the path of the folder, that contains the convert_wikilinks_to_markdown_links.py Python script."
-- On macOS < 12.3, set LocalPython to "/usr/bin/python". For higher macOS versions, install Python (e.g., via Anaconda.com or python.org), find out the path of your new Python installation (open a terminal and type "which python") and set LocalPython to the given result. The default setting below links to the Anaconda installation; in case you're also using Anaconda, please replace "<USER>" with your user name.
set LocalPython to "/Users/<USER>/opt/anaconda3/bin/python"
tell application id "DNtp"
try
set theNum to count of every selected record
if theNum is 0 then error "Please select some documents."
repeat with theRecord in every selected record
if type of theRecord is markdown then
set theText to plain text of theRecord
set theShellScript to LocalPython & " " & MyPythonScriptPath & "generate_toc_with_btt_links.py " & quoted form of theText
set TheNewText to do shell script theShellScript
--["Result ", TheNewText]
set plain text of theRecord to TheNewText
end if
end repeat
end try
end tell