Save as webarchive in Folder with a new name

I’m using this script to save Safari pages.


tell application "Safari"
	activate
	set theURL to front document
	tell application "System Events"
		tell process "Safari"
			tell menu 1 of menu bar item "File" of menu bar 1
				repeat while enabled of menu item "Save as." is false
					delay 0.1
				end repeat
			end tell
			keystroke "s" using command down -- Save As.
			repeat until sheet 1 of window 1 exists
				delay 0.1
			end repeat
			tell sheet 1 of window 1
				click pop up button 1 of group 1
				keystroke "S"

		end tell
	end tell
end tell

After the step “KEYSTROKE S” I would like to be able to paste the content of the clipboard as a file name, the content of the clipboard comes from a FMP field.

How can I achieve this?

Thanks a lot


tell application "Safari" to activate
set theURL to URL of front document of application "Safari"
set theFMPfieldText to the clipboard as text

tell application "System Events" to tell application process "Safari"
	tell menu 1 of menu bar item "File" of menu bar 1
		repeat while enabled of menu item "Save As…" is false
			delay 0.1
		end repeat
		click menu item "Save As…"
	end tell
	
	repeat until sheet 1 of window 1 exists
		delay 0.1
	end repeat
	
	tell sheet 1 of window 1
		click text field 1
		keystroke theFMPfieldText
		delay 0.5
		click pop up button 2
		repeat until (menu 1 of pop up button 2 exists)
			delay 0.1
		end repeat
		click menu item "Web Archive" of menu 1 of pop up button 2
		click UI element "Save"
	end tell
end tell