I am trying to import only the attachments from Mac mail into DT.
I can save them to desktop OK, but it fails when I try to import into DT.
The error I get is error "Can’t make «class DTpr» id 9 of «class DTkb» id 2 of application \"DEVONthink 3\" into the expected type." number -1700 from «class DTpr» id 9 of «class DTkb» id 2
Here is my code. Any advice gratefully received
-- set desktopPath to (path to desktop)'s POSIX path
tell application "Mail"
repeat with aMessage in (get selection)
repeat with theAttachment in mail attachments of aMessage
set attachmentName to name of theAttachment
tell application id "DNtp"
set theLocation to create location "/Inbox" in database "Filing"
set myRecord to import theAttachment to theLocation
end tell
-- save theAttachment in POSIX file (desktopPath & attachmentName)
end repeat
end repeat
end tell
There is already an application script available in the global Scripts menu in Apple Mail.
Aaah! Thanks, I’ll try and find that. I don’t use the global scripts menu
You’re welcome.
It can be a handy menu to use. Check it out.
I’ve found it now (thanks ) in ~/Library/Application Scripts/com.apple.mail/
but it doesn’t seem to import anything. No alerts or anything. Will investigate further
You run the script out of the global Scripts menu with an email having an attachment selected.
I just tested it and it’s working here.
Thanks Jim. Actually the Script Menu bar was already enabled - however it is still not showing. Obviously trying to fix that us out the scope of this, but I must admit I am struggling to find an answer.
This in itself does not bother me as I trigger all my scripts from either Alfred or Keyboard Maestro, however I am wondering whether this script can only be run from the script menu as the code is not a tell application "mail
but
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
Is there any option to amend my code with the tell application "Mail"
I will want to run it from alfred or KM anyhow
Actually the Script Menu bar was already enabled - however it is still not showing.
What is still not showing?
using terms from application “Mail”
on perform mail action with messages theMessages for rule theRule
This is from the mail rule script, not the script I mentioned.
Thanks @BLUEFROG
The Global Scripts menu is not showing and so I cannot run it from there.
When I went into the scripts folder for mail ~/Library/Application Scripts/com.apple.mail/
and opened the add attachments to Devonthink that is what I got, but yes I have just noticed that that is a mail rule script.
Can you let me know where I can find the other script you showed in your screengrab please?
EDIT: I suppose I could just put the screengrab into DT and OCR it
Open ~/Applications/Utilities/Script Editor
's Preferences > General and enable Script Menu: Show Script menu in menu bar.
This was already enabled, but nothing shows.
As I mentioned I am going to try and fix this outside of this forum, but I was more interested in the link to the actual script file in your screengrab.
Cool if not I will OCR the image file
I have OCR’d your image (and added missing code at the end) but I am getting an error…
import "/private/var/folders/c6/d50zfg297tj46zwtsskf4wxm0000gn/T/com.apple.mail/TemporaryItems/INVOICE CT0522-01.pdf" to parent id 2.147483645E+9 of database id 1
--> missing value
Any thoughts?
Many thanks as ever
Please post a screen capture of the menu bar when you’re in Apple Mail.
Are you using Bartender or a similar app to hide menubar icons?
Thanks yes for some reason it was in “always hidden,” however I am still getting the same missing value
error from this script.
The attachment is present in com.apple.mail/TemporaryItems
Just wondered whether anybody else had any thoughts on this missing value
error I am getting however I run the script?
Many thanks
The parent id in your screenshot is completely bogus. No ID can be a floating point number.
It’s actually not a floating point number but the valid ID of the database’s root group:
2.147483645E+9 => 2147483645
So the old adage „if it looks like a duck, walks like a duck,…“ doesn’t hold here. Another thing learned.