1. -- movie script "main"
  2. property __cx
  3.  
  4. on startMovie
  5.   script("main").__cx = xtra("Clipboard").new()
  6.   script("main").__cx.clipSetCallback(#clipboardChanged)
  7. end
  8.  
  9. on stopMovie
  10.   if not voidP(script("main").__cx) then
  11.     script("main").__cx.clipStopCallback()
  12.     script("main").__cx = VOID
  13.   end if
  14. end
  15.  
  16. on clipboardChanged
  17.   res = script("main").__cx.clipGetFormatsInClipboard()
  18.  
  19.   -- check if clipboard has "Rich Text Format" but no CF_UNICODETEXT
  20.   if res.getPos(49284)>0 and res.getPos(13)=0 then
  21.    
  22.     -- get RTF, convert to UTF-8 text
  23.     data = script("main").__cx.clipGetData(49284)
  24.     member("tmp").rtf = data.readRawString(data.length)
  25.     utf8Text = member("tmp").text
  26.    
  27.     -- convert UTF-8 to UTF-16
  28.     baUtf16 = bytearray()
  29.     baUtf16.writeString(utf8Text, "UTF-16")
  30.     baUtf16.writeInt16(0) -- append 2 null bytes
  31.     baUtf16.position = 5
  32.    
  33.     -- add missing CF_UNICODETEXT format to clipboard
  34.     script("main").__cx.clipAddData(13, baUtf16.readByteArray(baUtf16.length-4))
  35.    
  36.     --put "Clipboard fixed"
  37.   end if
  38. end
  39.  
[raw code]