If you run the Scripts from ExtendScript Toolkit what error or which line gets displayed at the bottom of the window at the halt?
When running Photoshop scripts in ESTK you need to set the target to Photoshop. You set that in the left dropdown at the top of the script window.
My guess is you are getting that error because ESTK is the target and preferences is a property of Photoshop's application object and is not defined when the target is ESTK.
I have found the way to launch the script from ESTK and I stay surprise to see that script run more smoothly. This is a work around but for now is a step forward. When the script stops, in ESTK the item that turn at the bottom of the window go away and all is normal. At the end of the script run
ESTK at the bottom tells "Exucution finished".
When the busy icon at the bottom and ESTK prints "Exucution finished" that means the script run without any errors.
I don't know why it would run in ESTK with Photoshop as the target and not run in Photoshop.