Below I paste a starting point for the actual (bash) script, converting #tw tagged lines within any Obsidian note into a proper Task Warrior event…
Yet, it remains to be seen how to launch (automatically) this script. It depends on the OS and its tricks to “notify upon file change” in a folder (see above the links I have shared).
On macOs (Big Sur) fswatch works well (home-brew) by invoking:
fswatch -o $HOME/Dropbox/notes | xargs -n1 -I{} myScript.sh
(see also the latency flag of fswatch)
Below the myScript.sh:
#!/usr/bin/env bash
#
# Path containing the md files to monitor..
myPath=$HOME/Dropbox/notes
# String to trigger the Task Warrior "add" command
trigger="#tw"
# String to replace the original trigger
trigrpl="#ok_tw"
# Remove these strings when creating the TW new task descr
extra1="- "
extra2="\[ ] "
extra3="\[x] "
# Use grep recursively, on all files (and subfolders)
# in $myPath, while ignoring binary files.
entries=$(grep -r -I "$trigger" $myPath/*)
# Use sed to remove any occurrence of $trigger & #extra1,2,3
clean=$(echo "$entries" | sed "s@$trigger@@g" | sed "s@$extra1@@g" | sed "s@$extra2@@g" | sed "s@$extra3@@g")
# Scan every line present in the output of grep
IFS='
'
for entry in $clean
do
# Use this bash expansion trick to remove all chars
# preceding the first ":" (see grep output format)
# That would be the "line" used to create a new task
if task add ${entry#*:} ; then
#echo "Command succeeded"
sed -i '' "s@$trigger@$trigrpl@g" "${entry%:*}"
# Only if TW succeeds, replace $trigger with $trigrpl
fi
done