Applescript export Pages to txt

Hello Applescripters !

I need to export a .pages document to .txt

I’ve written the following script, but I get error

tell application "Finder"
	set pagesFile to "Macintosh HD:Users:mohican:Documents:.pagesIntegration:Letter1.pages"
end tell
tell application "Pages"
	activate
	open pagesFile
	set txtFile to "Macintosh HD:Users:mohican:Documents:.pagesIntegration:Letter1.txt"
	export front document to txtFile as unformatted text
end tell

The error I get is

However, if I change the txtFile to …/Letter.txt the script runs successfully. Any other filename but that failed

Any idea why this happens ?

Thanks in advance

Here, I had to edit your code:

--tell application "Finder" -- USELESS
set pagesFile to "Macintosh HD:Users:mohican:Documents:.pagesIntegration:Letter1.pages" as «class furl» -- EDITED
--end tell -- USELESS
tell application "Pages"
	activate
	open pagesFile
	set txtFile to "Macintosh HD:Users:mohican:Documents:.pagesIntegration:Letter1.txt" as «class furl» -- EDITED
	export front document to txtFile as unformatted text
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 10 février 2021 11:37:31

Awesome it worked !

Thank you

You were passing strings when file references were needed.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 10 février 2021 12:22:22