Separate imported e-mail attachments for better search

tell application "DEVONthink 3"
get selection
	--> {content id 7383 of database id 3}
path to temporary items
	--> alias "Macintosh HD:private:var:folders:m6:k_6qdnr56tv0n68zkm08p55w0000gn:T:TemporaryItems:"
get type of content id 7383 of database id 3
	--> unknown
get path of content id 7383 of database id 3
	--> "/Users/aaronhand/Documents/Misison Viejo Elections.dtBase2/Files.noindex/eml/6/Fw_ Public Disclosure - Public Consent.eml"
convert record content id 7383 of database id 3 to rich
	--> content id 7429 of database id 3
get reference URL of content id 7383 of database id 3
	--> "x-devonthink-item://18FECA34-9069-4AE9-B30C-96572BC0725C"
get type of content id 7429 of database id 3
	--> rtfd
get path of content id 7429 of database id 3
	--> "/Users/aaronhand/Documents/Misison Viejo Elections.dtBase2/Files.noindex/rtfd/2/Fw_ Public Disclosure - Public Consent.rtfd"
get parent 1 of content id 7383 of database id 3
	--> parent id 7425 of database id 3
get name of content id 7383 of database id 3
	--> "Fw_ Public Disclosure - Public Consent"
get modification date of content id 7383 of database id 3
	--> date "Tuesday, June 8, 2021 at 12:15:39 AM"
get creation date of content id 7383 of database id 3
	--> date "Friday, May 21, 2021 at 2:15:07 PM"
get addition date of content id 7383 of database id 3
	--> date "Tuesday, June 8, 2021 at 12:41:07 AM"
exists attachment of every attribute run of every text of content id 7429 of database id 3
	--> true
end tell
tell application "Finder"
	get POSIX file "/Users/aaronhand/Documents/Misison Viejo Elections.dtBase2/Files.noindex/rtfd/2/Fw_ Public Disclosure - Public Consent.rtfd"
		--> error number -1728 from POSIX file "/Users/aaronhand/Documents/Misison Viejo Elections.dtBase2/Files.noindex/rtfd/2/Fw_ Public Disclosure - Public Consent.rtfd"
	get every file of alias "Macintosh HD:Users:aaronhand:Documents:Misison Viejo Elections.dtBase2:Files.noindex:rtfd:2:Fw_ Public Disclosure - Public Consent.rtfd:"
		--> {document file "Deputy AG Grievance highlights.pdf" of document file "Fw_ Public Disclosure - Public Consent.rtfd" of folder "2" of folder "rtfd" of folder "Files.noindex" of document file "Misison Viejo Elections.dtBase2" of folder "Documents" of folder "aaronhand" of folder "Users" of startup disk, document file "TXT.rtf" of document file "Fw_ Public Disclosure - Public Consent.rtfd" of folder "2" of folder "rtfd" of folder "Files.noindex" of document file "Misison Viejo Elections.dtBase2" of folder "Documents" of folder "aaronhand" of folder "Users" of startup disk, document file "multi card.png" of document file "Fw_ Public Disclosure - Public Consent.rtfd" of folder "2" of folder "rtfd" of folder "Files.noindex" of document file "Misison Viejo Elections.dtBase2" of folder "Documents" of folder "aaronhand" of folder "Users" of startup disk}
	get document file "Deputy AG Grievance highlights.pdf" of document file "Fw_ Public Disclosure - Public Consent.rtfd" of folder "2" of folder "rtfd" of folder "Files.noindex" of document file "Misison Viejo Elections.dtBase2" of folder "Documents" of folder "aaronhand" of folder "Users" of startup disk
		--> "Macintosh HD:Users:aaronhand:Documents:Misison Viejo Elections.dtBase2:Files.noindex:rtfd:2:Fw_ Public Disclosure - Public Consent.rtfd:Deputy AG Grievance highlights.pdf"
	get POSIX file "/Users/aaronhand/Documents/Misison Viejo Elections.dtBase2/Files.noindex/rtfd/2/Fw_ Public Disclosure - Public Consent.rtfd/Deputy AG Grievance highlights.pdf"
		--> error number -1728 from POSIX file "/Users/aaronhand/Documents/Misison Viejo Elections.dtBase2/Files.noindex/rtfd/2/Fw_ Public Disclosure - Public Consent.rtfd/Deputy AG Grievance highlights.pdf"
	move alias "Macintosh HD:Users:aaronhand:Documents:Misison Viejo Elections.dtBase2:Files.noindex:rtfd:2:Fw_ Public Disclosure - Public Consent.rtfd:Deputy AG Grievance highlights.pdf" to alias "Macintosh HD:private:var:folders:m6:k_6qdnr56tv0n68zkm08p55w0000gn:T:TemporaryItems:" with replacing
		--> document file "Deputy AG Grievance highlights.pdf" of folder "TemporaryItems" of folder "T" of folder "k_6qdnr56tv0n68zkm08p55w0000gn" of folder "m6" of folder "folders" of folder "var" of item "private" of startup disk
		--> error number 0
	get document file "Deputy AG Grievance highlights.pdf" of folder "TemporaryItems" of folder "T" of folder "k_6qdnr56tv0n68zkm08p55w0000gn" of folder "m6" of folder "folders" of folder "var" of item "private" of startup disk
		--> "Macintosh HD:private:var:folders:m6:k_6qdnr56tv0n68zkm08p55w0000gn:T:TemporaryItems:Deputy AG Grievance highlights.pdf"
end tell
tell application "DEVONthink 3"
	create record with {name:"Fw_ Public Disclosure - Public Consent", type:group, modification date:date "Tuesday, June 8, 2021 at 12:15:39 AM", creation date:date "Friday, May 21, 2021 at 2:15:07 PM", addition date:date "Tuesday, June 8, 2021 at 12:41:07 AM"} in parent id 7425 of database id 3
		--> parent id 7431 of database id 3
	import "/private/var/folders/m6/k_6qdnr56tv0n68zkm08p55w0000gn/T/TemporaryItems/Deputy AG Grievance highlights.pdf" to parent id 7431 of database id 3
		--> missing value
end tell
tell application "Finder"
	get document file "TXT.rtf" of document file "Fw_ Public Disclosure - Public Consent.rtfd" of folder "2" of folder "rtfd" of folder "Files.noindex" of document file "Misison Viejo Elections.dtBase2" of folder "Documents" of folder "aaronhand" of folder "Users" of startup disk
		--> "Macintosh HD:Users:aaronhand:Documents:Misison Viejo Elections.dtBase2:Files.noindex:rtfd:2:Fw_ Public Disclosure - Public Consent.rtfd:TXT.rtf"
	get document file "multi card.png" of document file "Fw_ Public Disclosure - Public Consent.rtfd" of folder "2" of folder "rtfd" of folder "Files.noindex" of document file "Misison Viejo Elections.dtBase2" of folder "Documents" of folder "aaronhand" of folder "Users" of startup disk
		--> "Macintosh HD:Users:aaronhand:Documents:Misison Viejo Elections.dtBase2:Files.noindex:rtfd:2:Fw_ Public Disclosure - Public Consent.rtfd:multi card.png"
end tell
tell application "DEVONthink 3"
	move current application record content id 7383 of database id 3 to parent id 7431 of database id 3
		--> content id 7383 of database id 3
	delete current application record content id 7429 of database id 3
		--> true
end tell
Result:
true

If it helps, I cleared that temp folder and re-ran the script on the same item. It looks like the same output in Script Editor, though I did confirm that the attachment was extracted and saved into the temp folder.
Screen Shot 2021-06-08 at 10.18.26 AM

It’s not easy to debug remotely, but for some reason the “import” statement is returning “missing value” like it isn’t able to import the attachment. Maybe the Log or Activity window is showing some information of why the attachment can’t be imported?

Interesting – lack of permissions? I am able to navigate to that folder and interact with the file. Is MacOS somehow preventing DT or AppleScript from access the folder (even though the created the contents in it)?

I was in the process of granting DT full control when I knocked my Nalgene of water with perfect precision to irrigate my MBP. So I’ll helpfully report back one Day whether that fixes things — after we see about the logic board.

1 Like

DEVONtech don’t advocate that solution.

(On a more serious note: I wish you a speedy, preferably free recovery without loss of data. Thumbs pressed).

:flushed::cry:
I once fatally spilled a fresh 20oz latte on a corporate-issued MacBook Pro. Fingers crossed for you.

Not sure - maybe DT engineering can shed a light on this? Maybe Full Disk Access or something else has to be enabled? Or you can trying making a script that just simply tries to import that specific file to single out any other things that might be going on. First let’s hope your Macbook gets fixed!

Well, I’m back in business after a replacement logic board, top case, touch bar, display, and lid angle sensor … “happy” that I got AppleCare Plus when I bought it!

I granted DevonThink and Script Editor full disk access in the Security & Privacy preference pane, but still get an error in the log about accessing a sub-folder in the TemporaryItems folder.

Is there another process or application involved in executing the script?

2 Likes

Do you see the issue on a new macOS account on the machine?

Yes (new admin account, same error). In Catalina if that makes a difference.

Yes (new admin account, same error)

Just be clear… you mean a brand new account you just created, not ”brand new” meaning your current account, post-fixed Mac, correct?

Correct. I created a new admin user, a new database, imported one email with attachment (exported from gmail web), and then tried running the script from Script Editor and by adding it to the script menu.

Select a file in the temp folder and press Option-Command-C to copy the path.
Then paste it in the second line of this script, obviously setting the database name applicable to you…

tell application id "DNtp"
	import "/private/var/folders/x5/kkn53tmn1wb2zc4t1z0j6cgc0000gn/T/mat-debug-15053.log" to (root of database "7")
end tell

Does it import as expected when you run the script?

I get a similar error … though looking at the path, the item that I don’t have permission to access (e.g., “b”) is not a directory in the path.

Would it matter if I have both the older version of DevonThink Pro, as well as DevonThink 3 installed? Both have Full Disk Access and Automation rights in the Security & Privacy control panel.

No you should not have both installed, at least not on the same account. But even then it’s not a good idea unless you’re setting per account permissions to hide one version.

Short answer: If you have transitioned to version 3, delete the 2.x application, and reboot the Mac.

I recently purchased DT3. I deleted 2 and rebooted; still no luck.

In the debug window in Script Editor, I am seeing this type of error:

tell application “Finder”

get POSIX file “/Users/aaronhand/Documents/Misison Viejo Elections.dtBase2/Files.noindex/rtfd/9/FW_ Records Request - CVRA lawsuit.rtfd”

error number -1728 from POSIX file “/Users/aaronhand/Documents/Misison Viejo Elections.dtBase2/Files.noindex/rtfd/9/FW_ Records Request - CVRA lawsuit.rtfd”

If I put a delay command into the script and navigate into that directory in the database package, I do see that a .rtfd document was created and exists in that location.

practically i think evaluating the needs from 300000 emails and it´s attachments is a crazy amount of work. i mentioned that problem to devonthink a long time ago, but it seems, mdbraber solve the problems of not indexed email attachments in devonthink for devonthink. so we all should thank mdbraber and not just write “you don´t need all…” what about other users that expect to find emails AND documents INSIDE devonthink. The most will not recognize that they attach 5mb Trash PDF files inside a eml INSIDE devonthink and get NO ADVANTAGE from it. So my big Question is. Maybe Bluefrog uses it only for Printing the E-Mails? Why we have an “special E-Mail Plugin und special E-Mail Import in devonthink” if you cannot find the same amount of Informations as you have in the Mail.app from Apple ?

@aaronhand you just need to give the Correct Rights inside “Full Drive Access” in “Security” of OSX for DevonThink 3, and run the Script. It can import the Files as described.