commit 6c5b66b61ebea1771afec5c586ca11a7e1438e4c Author: thanhtl Date: Fri Feb 28 16:14:21 2025 +0700 Add paperless.script diff --git a/paperless.script b/paperless.script new file mode 100644 index 0000000..c0388bf --- /dev/null +++ b/paperless.script @@ -0,0 +1,57 @@ +-- AppleScript to upload selected DEVONthink items to Paperless-ngx +-- Uses the "URL" field as Paperless title and "tags" as Paperless tags. + +tell application "DEVONthink 3" + set theSelection to the selection + if theSelection is {} then + display alert "No documents selected in DEVONthink." + return + end if + + repeat with theRecord in theSelection + set docPath to path of theRecord + set docURL to aliases of theRecord & "_" & URL of theRecord -- Title in Paperless + set recordTags to tags of theRecord -- List of DEVONthink tags + + if docPath is not missing value and docPath is not "" then + + -- Your Paperless token + set paperlessToken to "59760e42725bf98ac0345fd2ec9f754cf053a8d5" + + -- Path to Python script + set uploadScriptPath to "/Users/z/Documents/upload.py" + + -- Convert tags list to a string with '||' as delimiter + set tagString to "" + if (count of recordTags) > 0 then + repeat with t in recordTags + set tagString to tagString & t & "||" + end repeat + -- Remove trailing '||' + if tagString ends with "||" then + set tagString to texts 1 thru -3 of tagString + end if + end if + + if docURL is missing value or docURL is "" then + set docURL to "Untitled" -- Fallback title + end if + + -- Build shell command to call Python script + set shellCommand to "/Users/z/venv/bin/python " & uploadScriptPath & space & ¬ + quoted form of docPath & space & paperlessToken & space & ¬ + quoted form of docURL & space & quoted form of tagString + + try + do shell script shellCommand + display notification "Uploaded " & (name of theRecord) & " to Paperless." with title "Paperless Upload" + on error errMsg + display alert "Error uploading " & (name of theRecord) & ": +" & errMsg + end try + + else + display alert "Record " & (name of theRecord) & " does not have a valid file path." + end if + end repeat +end tell