Multiple Images to Notes (again!)

I want to send several images (usually less than 10) to a Notes file on my Mac. This is part of a larger project which I have been working on for ages, on and off (including loads of help from users on here - thanks).

I have 2 scripts below:

For the first one I hard code the Image names to a list and all works fine.

For the second script, I want to just select the directory where the images are located but have come up against some sort of file reference / alias issue. Hopefully I have explained what is happening in the Script comments but please let me know if you need more info.

Can someone let me know where I have gone wrong please?

Thanks.

** Code Below **

Try again…

-- ** SCRIPT 1 - IMAGES AS VARIABLE (ALIAS) Works fine.


set ImageLst to {alias "Macintosh HD:Users:MyName:Desktop:Images:FrontPic_000.jpg", alias "Macintosh HD:Users:MyName:Desktop:Images:ReportPic_001.jpg", alias "Macintosh HD:Users:MyName:Desktop:Images:ReportPic_002.jpg", alias "Macintosh HD:Users:MyName:Desktop:Images:ReportPic_003.jpg", alias "Macintosh HD:Users:MyName:Desktop:Images:ReportPic_004.jpg"}

-- Add to Notes
set backgroundColor to "white"
set titleFontColor to "green"
set messageFontColor to "red"
set title to "Building Picture"
set message to "New image added"

set |note body| to "
   <body>
<h1 style=\"color:" & titleFontColor & ";background-color:" & backgroundColor & ";font-family:Helvetica,sans-serif;font-size:18;bold:false\">" & title & "</h1> 
<p style=\"color:" & messageFontColor & ";background-color:" & backgroundColor & ";font-family:Helvetica,sans-serif;font-size:24;bold:false;\" >" & message & "</p>
</body>"

tell application "Notes"
	tell account "On My Mac" to tell folder "Notes"
		--tell account "Icloud" to tell folder "Notes"
		-- make new note
		set theNote to make new note with properties {body:|note body|}
		-- get its id
		try
			set theID to id of theNote
		on error errorMessage
			set ATID to AppleScript's text item delimiters
			set AppleScript's text item delimiters to "\""
			set theID to text item 2 of errorMessage
			set AppleScript's text item delimiters to ATID
		end try
		repeat with aListReference in ImageLst
			-- embed the picture
			make new attachment at end of attachments of note id theID with data (contents of aListReference)
		end repeat
	end tell
	save
end tell



-- ** SCRIPT 2 - SELECT DIRECTORY

(*
-- Get Images by selecting the directory. This only works if the script above (using alias is run first). Then this works, but only for the images that have already been "alias" previously.  
--IE: Even if there are 10 Images in the selected folder, only the ones (000 to 004 - already used above) are displayed in Notes. 
-- If Script 1 has not been run first, then no images will be displayed.

set ImageLst to {}
set theFolder to choose folder with prompt "Please select a folder:"
tell application "Finder" to set theFiles to get every file of folder theFolder

repeat with currentFile in theFiles
	set ImageFile to (the name of currentFile) as text
	
	set Test1 to "Macintosh HD:Users:MyName:Desktop:Images:" & ImageFile as text
	copy Test1 to the end of ImageLst
end repeat

-- Add to Notes
set backgroundColor to "white"
set titleFontColor to "green"
set messageFontColor to "red"
set title to "Building Picture"
set message to "New image added"

set |note body| to "
   <body>
<h1 style=\"color:" & titleFontColor & ";background-color:" & backgroundColor & ";font-family:Helvetica,sans-serif;font-size:18;bold:false\">" & title & "</h1> 
<p style=\"color:" & messageFontColor & ";background-color:" & backgroundColor & ";font-family:Helvetica,sans-serif;font-size:24;bold:false;\" >" & message & "</p>
</body>"

tell application "Notes"
	tell account "On My Mac" to tell folder "Notes"
		--tell account "Icloud" to tell folder "Notes"
		-- make new note
		set theNote to make new note with properties {body:|note body|}
		-- get its id
		try
			set theID to id of theNote
		on error errorMessage
			set ATID to AppleScript's text item delimiters
			set AppleScript's text item delimiters to "\""
			set theID to text item 2 of errorMessage
			set AppleScript's text item delimiters to ATID
		end try
		
		repeat with aListReference in ImageLst
			-- embed the picture
			make new attachment at end of attachments of note id theID with data (contents of aListReference)
		end repeat
	end tell
	save
end tell
*)

Easier, when you know what to look for…

-- ** SCRIPT 2 - SELECT DIRECTORY

set theFolder to (choose folder)
tell application "Finder" to set ImageLst to files of theFolder as alias list

-- Add to Notes
set backgroundColor to "white"
set titleFontColor to "green"
set messageFontColor to "red"
set title to "Building Picture"
set message to "New image added"

set |note body| to "
   <body>
<h1 style=\"color:" & titleFontColor & ";background-color:" & backgroundColor & ";font-family:Helvetica,sans-serif;font-size:18;bold:false\">" & title & "</h1> 
<p style=\"color:" & messageFontColor & ";background-color:" & backgroundColor & ";font-family:Helvetica,sans-serif;font-size:24;bold:false;\" >" & message & "</p>
</body>"

tell application "Notes"
	tell account "On My Mac" to tell folder "Notes"
		--tell account "Icloud" to tell folder "Notes"
		-- make new note
		set theNote to make new note with properties {body:|note body|}
		-- get its id
		try
			set theID to id of theNote
		on error errorMessage
			set ATID to AppleScript's text item delimiters
			set AppleScript's text item delimiters to "\""
			set theID to text item 2 of errorMessage
			set AppleScript's text item delimiters to ATID
		end try
		
		repeat with aListReference in ImageLst
			-- embed the picture
			make new attachment at end of attachments of note id theID with data (contents of aListReference)
		end repeat
	end tell
	save
end tell