-- DEVONthink 4 Smart Rule: OmniFocus 연동 -- Projects DB 새 문서에서 TODO 패턴 감지 → OmniFocus 작업 생성 -- Smart Rule 설정: Event = On Import, DB = Projects on performSmartRule(theRecords) tell application id "DNtp" repeat with theRecord in theRecords try set docText to plain text of theRecord set docTitle to name of theRecord set docUUID to uuid of theRecord set docLink to reference URL of theRecord -- x-devonthink-item://UUID -- TODO 패턴 감지: "TODO", "할일", "□", "[ ]", "FIXME" set hasAction to false if docText contains "TODO" or docText contains "할일" or docText contains "□" or docText contains "[ ]" or docText contains "FIXME" then set hasAction to true end if if not hasAction then continue repeat -- 액션 아이템 추출 (Python으로 파싱) set extractCmd to "echo " & quoted form of docText & " | python3 -c \" import sys, re text = sys.stdin.read() patterns = [ r'(?:TODO|FIXME|할일)[:\\s]*(.+?)(?:\\n|$)', r'(?:□|\\[ \\])\\s*(.+?)(?:\\n|$)', ] items = [] for p in patterns: items.extend(re.findall(p, text, re.MULTILINE)) # 최대 5개, 중복 제거 seen = set() for item in items[:10]: item = item.strip() if item and item not in seen: seen.add(item) print(item) if len(seen) >= 5: break \"" set actionItems to paragraphs of (do shell script extractCmd) if (count of actionItems) = 0 then continue repeat -- OmniFocus에 작업 생성 tell application "OmniFocus" tell default document set taskIDs to {} repeat with actionItem in actionItems set taskName to docTitle & " — " & (contents of actionItem) set newTask to make new inbox task with properties {name:taskName, note:"DEVONthink 문서: " & docLink} set end of taskIDs to id of newTask end repeat end tell end tell -- DEVONthink 메타데이터에 OmniFocus Task ID 저장 set AppleScript's text item delimiters to "," set taskIDString to taskIDs as text set AppleScript's text item delimiters to "" add custom meta data taskIDString for "omnifocusTaskID" to theRecord on error errMsg do shell script "echo '[" & (current date) & "] [omnifocus_sync] [ERROR] " & errMsg & "' >> ~/Documents/code/DEVONThink_my\\ server/logs/omnifocus_sync.log" end try end repeat end tell end performSmartRule