Save Notes.app attachment does not work on El Capitan

Hi,
i’am a Noobie on this forum and in the Applescript.

Recently, I wrote a script that stores the Notes attachment to a file on disk. Script works fine on all later OS X versions except of 10.11. I think I have a problem with some kind of sand-boxing limitations of Notes.app on El Capitan.
This is applescript code example:


set homeFolderPosix to (system attribute "HOME")

-- Sandboxing limits access to Notes.app' own container. This location works up to Yosemite 
set tmpExportFolderPosix to homeFolderPosix & "/Library/Containers/com.apple.Notes/Data/tmp_exported/" as string
--set tmpExportFolderPosix to homeFolderPosix & "/Library/Containers/com.apple.Notes.HTMLConverter/Data/tmp_exported/" as string

set tmpExportFolder to ((tmpExportFolderPosix as POSIX file) as string)

do shell script "mkdir -p " & quoted form of tmpExportFolderPosix
-- Clean out any attachments that may be left over from previous failed run
do shell script "rm -f " & quoted form of tmpExportFolderPosix & "*"

set attCounter to 0
tell application "Notes"
	tell account "On My Mac" to tell folder "Notes" to set theNote to note "TEST123"
	set theAttachs to every attachment of theNote
	if (count of theAttachs) > 0 then
		repeat with att in theAttachs
			set attCounter to attCounter + 1
			set attFName to attCounter & "_" & (name of att) as string
			set attFile to ((tmpExportFolderPosix & attFName) as string)
			save att in attFile
		end repeat
	else
		log ("No attachments found in the " & noteTitle & " note!")
	end if
end tell


Does anyone know correct location where is allowed to save a file with the attachment?

Thanks!

I’m not sure that the problem is related to the destination folder.
I tried with several folders in which I commonly store files with the same behavior : the save command fails silently.
I’m wondering if it’s related to a surprising behavior

id of att # works
log result
container of att  # works
log result
content identifier of att # works
log result
properties of att # fails : error "Erreur dans Notes : La lecture n'a pas été autorisée." number -10005 from properties of attachment id "x-coredata://4D94098A-E74D-47DE-91C8-E84269FBD284/Attachment/p2"
log result

Why extracting properties one by one works but extracting them all at once fail ?

Yvan KOENIG running El Capitan 10.11.3 in French (VALLAURIS, France) dimanche 6 mars 2016 21:51:31