Well it looks like nothing has change since 2012 in this subject, so i'm wondering what's wrong?

Then post your code. For code formatting in the Forum you need the "Use advanced editor" feature. Select the code, go to >> Insert and do: Syntax Highlighting > javascript. You have to scroll a bit down to see this option.

Just tested Vamitul's code in answer #25 with InDesign CC 2018.1 on Windows 10. It is doing exactly what it should. RGB images in JPEG format with 300 ppi effective resolution. If you want CMYK you have to change line 15.

From:

prfs.jpegColorSpace = JpegColorSpaceEnum.RGB;

To:

prfs.jpegColorSpace = JpegColorSpaceEnum.CMYK;

I also tested this. No problem on my side…

So again. Post your code. Maybe something's went wrong by copy/paste it ?