I'm working on a script that copies Apple Mail mails into Apple Notes. So far so good, but I am having troubles getting the attachments into the newly created note. This is on macOS Catalina 10.15.7.
I spent half a day yesterday looking for solutions, but they all do not work.
When I execute a make new attachment statement, I get the following kind of error for each attachment found in the email: Notes got an error: Can’t make show id "x-coredata://32E6D9EF-97F3-424F-B151-DD166A00E0AB/ICNote/p9725" into type specifier. This UID is the same for each attachment.
I tried various path variations (as POSIX file, as text, or just as is) but all give the same error.
This simple code example already gives the error on line 2:
set theNote to make new note at folder NotesFolder with properties {body:theBody}
make new attachment at theNote with data theFileName
where theFileName is the complete path to the email-attachment, temporarily saved in a folder on the desktop so Applescript and Notes can have access to it.
Since the UID in the error message is the same for every found attachment, it can also be that theNote is not ok.
Any ideas what is wrong with this? Or is it Notes having problems (I've read that Notes in Catalina seems to have Applescripting bugs)
I'm at a loss, currently, so any help is much appreciated.
Can you create an attachment like so specifying your folder, account, and note id:
tell application "Notes"
activate
set theNote to make new note in folder "AB" of account "On My Mac" with properties {name:"3038665"}
tell theNote
make new attachment at end of attachments with data "/Users/xyz/Desktop/ab_download/test.jpg"
end tell
end tell
Related
I'm new to AppleScript and i'm trying to figure this out.
I'm trying to add an attachment for an email and I can get the image with
tell msg to make new attachment with properties {file name:"/Users/jarrod/Library/img/image.png"} at after the last paragraph
but I want the script to be dynamic and work on other computers so I tried
tell msg to make new attachment with properties {file name:"~/Library/img/image.png"} at after the last paragraph
but it can't find the image...
If I paste the path and search for it in my browser it comes up...
~/Library/img/image.png
Someone please tell me why this isn't working or if you know of a work around to get to the users folder name in AppleScript.
You can set a path like this:
set myPath to POSIX path of (path to library folder from user domain) & "img/image.png"
I am trying to incorporate my applescript into xcode. the script works normally with applescript but not ran in xcode. I am trying to open the file for reading. here is the code
set Location to "US"
set DriverFile to "/Volumes/MacPrintDrivers/" & Location & "DriverInstall.txt"
set DriverInstallFile to POSIX file DriverFile
open for access DriverInstallFile
i have confirmed the file exists and i can display the contents. i can't seem to read this way in Xcode. the error i get is
«script» doesn’t understand the «event rdwropen» message. (error -1708)
ASOC (AppleScript Objective-C) has some problems with scripting addition commands (such as open for access). Sometimes you can work around this by saying tell current application to, e.g. tell current application to open for access. But for further details I suggest you get Shane Stanley's book: http://www.macosxautomation.com/applescript/apps/ He has explored this in great depth.
I am having significant issues creating a very simple AppleScript to export attachments from an Evernote note. I have used the following code several times and it seems to work, but in actuality it fails silently, even though the event log shows a correct response.
I have heard that Evernote's recent versions have significant AppleScript support issues. If someone out there is an Evernote and AppleScript "expert", I would also greatly appreciate a review of my script to make certain I'm not forgetting anything.
I am using Mac OS X 10.8.2 and the Mac App Store version of Evernote 5.0.5 (400805).
Code:
set ExportPath to "LegatusHD1:Users:me:Downloads:Test"
set theAttachments to {}
set selectedItems to {}
tell application "Evernote"
set selectedItems to selection
repeat with selectedItem in selectedItems
set theAttachments to (attachments of selectedItem)
repeat with theAttachment in theAttachments
set theFilename to (ExportPath & ":" & theAttachment's filename)
write theAttachment to theFilename
set theFilename to ""
end repeat
end repeat
end tell
Apple has introduced sandboxing for apps from the AppStore recently. So depending on your OSX version, this might be the reason why it fails silently - since the Evernote app is not able to access the file system outside its own folder structure. You can try setting the export path to be something within the Evernote folder.
This question is old but I just tripped over it looking for an answer which I can now provide:
FYI I am running: OSX 10.9.1 (Mavericks) and Evernote 5.4.4 installed via App Store.
I can confirm that Mustafa was right, using the App Store version of the app it is only possible to write to files within the sandbox (/Users/{username}/Library/Containers/com.evernote.Evernote/)
Short answer
Either install the app from the Evernote website or if you want to use the one in the App Store:
Using the above script change the export path to something inside the sandbox e.g.:
set ExportPath to "Users:{username}:Library:Containers:com.evernote.Evernote:Data:attachment_export"
Remember to make the attachment_export folder first, and replace the {username} with your username
A note on debugging
Unfortunately applescript editor doesn't show any errors when you try to write outside the sandbox. You can however view the error in the Console application (found in Applications -> Utilities). In Console enter 'sandbox' in the search box (top right hand corner) and at the bottom of the window you will see something like this:
1/29/14 10:22:29.426 sandboxd[310]: ([4433]) Evernote(4433) deny file-write-create /Users/{username}/Desktop/Evernote Snapshot 20140128 134741.jpg
With 10.8, My Applescript (developed when I was running 10.4 thru 10.6) that reads a comma separate text file, uses the values to create a new mail message, then attachs a xx.pdf file using a NSstring path name to the file, still sends out the email, but does not include the attachment. I understand from researching the problem, that 10.8 security enhancements have "SANDBOXed" the Mail app and applescript apps so that the path name no longer works as a valid, passible link to the file. I have found several examples that claim to fix the problem, Claiming that the NSstring "file name:" must be replaced with file name in NSURL format, but the code does not look like applescript, and will not compile in the applescript editor. Do you have an example of applescript that will attach the file to a new, applescript generated email message? I have been trying for days to solve this problem without success. I even called the Apple Support line, but they said the do not support Applescript related problems any more.
The variable that I pass in from the text file is named "theAttachment1". The line I am trying to get working is:
"make new attachment with properties {file name:theAttachment1} at after the last paragraph
Again, it works fine in 10.4 thru 10.6, but will not work in 10.8.
This works for me on 10.8
set theAttachment1 to POSIX file "/Users/USERNAME/Desktop/Desktop--IMAGE/scooter-6.jpg"
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:"subject", content:"the_content" & return & return}
tell newMessage
set visible to false
set sender to "myaddress#btinternet.com"
make new to recipient at end of to recipients with properties {address:"someAddress#btinternet.com"}
make new attachment with properties {file name:theAttachment1} at after the last paragraph
(* change save to send to send*)
save --<<<<---------------- change save to send to send
(* change save to send to send*)
end tell
end tell
The path can be either a Unix path :"/Users/USERNAME/Desktop/Desktop--IMAGE/scooter-6.jpg"
or a Posix file path : "Macintosh HD:Users:USERNAME:Desktop:Desktop--IMAGE:scooter-6.jpg"
In this script I converted the path from a Unix path to a Posix file path
I'm trying to make two copies of an AppleScript, one that works for Entourage and one for out Outlook. I only have Entourage installed on the current computer.
According to the info on Microsoft's site, both applications have the same library of AppleScript commands, and I should be able to simply change the application name referenced within the script.
Changing:
Tell application "Microsoft Entourage"
to
Tell application "Microsoft Outlook"
Prevents me from saving the script because I don't have outlook installed on this computer. Is there any way around this? Do I need to use a text editor to edit the actual script file and change it there?
Thanks!
The following work-around may do the trick. On the computer where Entourage is installed, a using terms directive will let you compile the script, even if Outlook is not installed:
set theApp to a reference to application "Microsoft Outlook"
using terms from application "Microsoft Entourage"
tell theApp
get version
...
end tell
end using terms from
Upon compiling and saving the script the AppleScript Editor will bug you about the missing Outlook application, but it will nevertheless produce a compiled AppleScript file (.scpt).
Applescript is a pre-complied file format, meaning that every time you click "Save" it runs through a series of steps to ensure the script will work, but just short of actually running through the script's logic. Part of those steps is to look for the application to see if it exists on the Mac.
In short, if you want to save the script as an Applescript, you need the target application installed, otherwise you can save the script as a text file and move the file over to the target Mac to save as an Applescript over there.
It should be possible to make one script that works with both Entourage and Outlook, without bugging you if one isn't found either when you compile or when you run. I don't have either Entourage or Outlook but it should work like this:
using terms from application "Microsoft Entourage"
script theScript
tell application "Finder" to try
set theApp to application file id "Entourage's Bundle ID" as text
on error
set theApp to application file id "Outlook's Bundle ID" as text
end try
tell application theApp
-- do stuff
end tell
end script
end using terms from
store script theScript in "MyScript.scpt"
"using terms from" is only relevant when compiling the script - it isn't needed when running, though for some reason you'll still get bugged if that app isn't found. So by wrapping it around a script object and then writing out that script to file, the resultant script will still run but won't contain "using terms from" and so won't bug the user.
For getting a reference to the right app, Finder can look for it by ID and simply error if it isn't found rather than bugging the user. You'll need to insert the proper ID's there, I don't know what they are.