I could tell you three specific errors I do see in your code, but I don't think that's what you want. I think you want the problem solved. So I won't tell you about the errors that I see, because that won't fix your problem.
You cited a script by Nige, but you didn't provide the link to the page where that script is, or the script itself, so I can't refer to it. I suspect you are referring to this page:
From reading that thread, it looks like your original problem was solved. Now you have opened a new thread with the title "convert clipboard -> RTFD -> Pages format." But that's not enough information, because it's impossible to convert a clipboard to RTFD using the KM Write action if the clipboard does not already contain an RTFD flavour. If it does contain an RTFD object, then no conversion is necessary.
If your clipboard already contains an RTFD flavoured object, then you don't need to convert it to RTFD, (and you can't convert it with the Write action in KM anyway) all you need to do is convert it to pages, and that's what Nige's script seems to do. If you are trying to create an RTFD document from scratch, then you need to use an application that can create RTFD documents, like TextEdit. Pages cannot do it.
I would like to know why you are trying to convert a clipboard to RTFD. How are you putting an object into the clipboard? What app is running when the clipboard is given an object? What are the flavours of the object that you put into the clipboard? After you create the clipboard, you should run the following command in a Terminal window and show us the result:
osascript -e 'clipboard info'
If you show us the output of this command after placing the same item into the clipboard that you are trying to convert to an RTFD package, we might spot the problem. But you have to manually type the command into Terminal, as opposed to pasting it in there.