Yep, nearly there except I didn’t realize that the color has to be replaced in two places.
I guess it’s just a matter of running that replace routine twice. Could you do that for me, please?
set desktopPath to path to desktop as Unicode text
say "choose file file one"
set repText to read (choose file with prompt "Choose file1" without invisibles)
-- the text to replace after <BODY......
say "choose file file two"
set java2 to read (choose file with prompt "Choose file2" without invisibles)
say "choose web page file"
set html to read (choose file with prompt "Choose web page file" without invisibles)
-- insert the javascript before </HEAD>
set {TID, text item delimiters} to {text item delimiters, "</HEAD>"}
set {i1, i2} to text items of html
set html to java2 & i2
set text item delimiters to TID
set html to i1 & html
-- replace the string after <BODY (inclusive >) with repText
set text item delimiters to "<BODY "
set {i1, i2} to text items of html
set text item delimiters to TID
set html to i1 & "<BODY " & repText & text ((offset of ">" in i2) + 1) thru -1 of i2 --*)
say "choose colour for pop up"
set colorList to choose color
set htmlColor to ""
repeat with i in colorList
set htmlColor to htmlColor & text -2 thru -1 of ("0" & (do shell script "perl -e 'printf(\"%X\", " & i div 256 & ")'"))
end repeat
set {TID, text item delimiters} to {text item delimiters, "#HJFRKC"}
set html to text items of html
set text item delimiters to "#" & (htmlColor as string)
set html to html as text
set text item delimiters to TID
set ff to open for access file (desktopPath & "newpage.htm") with write permission
write html to ff
close access ff
say "saving file newpage to your desk top"