The following script uses 2 images from a website, puts their URL into HTML and then creates a Notes file showing the two images. All working fine.
The same 2 images are also saved to my Mac and I want to create the exact same Notes file in the same way but using the saved images instead of the website URL.
This is part of a bigger problem that I am stuck with but can someone please help me with the format of the second example of LstImageURL to get it working.
Thanks.
-- ** Website picked at random for example purposes **
set LstImages to {}
-- Working
set LstImageURL to {"https://cccbr.org.uk/wp-content/uploads/2016/05/howdenMinsterBells.jpg", "https://cccbr.org.uk/wp-content/uploads/2016/10/whitechapel-handbells.jpg"}
-- Not Working
--set LstImageURL to {"Macintosh HD:Users:Myname:Images:howdenMinsterBells.jpg", "Macintosh HD:Users:Myname:Images:whitechapel-handbells.jpg"}
repeat with i from 1 to length of LstImageURL
set ImageURL to "<img src=\"" & item i of LstImageURL & "\"<p><p>"
copy ImageURL to the end of LstImages
end repeat
set ReportImages to items of LstImages
tell application "Notes"
set the noteBody to "<html>
<p><span style=\"color:#FF0000\">Pictures: </span>
<p>" & ReportImages & "
<p><span style=\"color:#FF0000\">End of Pictures: </span>
</html>"
set thisAccountName to "My name" -- For testing (images appear immediately in the note)
--set thisAccountName to "Icloud" -- (Sometimes a delay for the images to appear)
-- make a new note at the top application-level:
make new note at folder "Notes" of account thisAccountName with properties {body:noteBody}
end tell
noteBody
What you are doing is using alias that you have converted to string. That is not a URI string
or same thing.
The way I do it I make absoluteString from NSURL class in ASObjC.
use framework "Foundation"
use scripting additions
set thePath to POSIX path of (path to home folder)
set theURL to (current application's |NSURL|'s fileURLWithPath:thePath)'s absoluteString() as string
Or if you do not like to use that you could do.
set thePath to POSIX path of (path to home folder)
set URISchema to "file://"
set theURL to URISchema & thePath
Fredrik71 - Thanks for your work on this but regrettably, I am no further forward here. I don’t really understand much of the information at the links but the 2 Scriptlets you supplied seem to just produce the same format that robertfern suggested
To add the local image file’s content, @Fredrik71 and me already shown to you how to embed the picture into the note, using Base64 picture encoding, or using make new attachment command.
tell application "Notes"
tell folder <YOUR_FOLDER_NAME> to tell note <YOUR_NOTE_NAME>
its properties
end tell
end tell
From the body property you could see how the core data is build and it use base64 encoding.
Same data is synced with iCloud so you are able to read it on other device. It wouldn’t be possible to read data from mobile device if the property used file:// or URL to local computer.
So any image in Notes are encoded and stored in iCloud as Base64 encoding.
It was wrong for me to suggest you could use file:// schema when I forgot you used Notes.