Postprocessing script encoding problem

It was suggested I post this question here instead of as a reply to the original thread:

I am using AmberV’s great little splitter script from this discussion:

In that thread it was already mentioned that

The solution suggested was to add the line


at the beginning of the script.
However, this did not resolve the issue in my case.
I am getting the following message:

[code]/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/delegate.rb:341:in write': U+00E9 from UTF-8 to US-ASCII (Encoding::UndefinedConversionError) from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/delegate.rb:341:in print’
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/delegate.rb:341:in block in delegating_block' from /var/folders/11/yyzl685d0h11s7ctdldn02pc0000gn/T/my-script:26:in block in ’
from /var/folders/11/yyzl685d0h11s7ctdldn02pc0000gn/T/my-script:13:in each' from /var/folders/11/yyzl685d0h11s7ctdldn02pc0000gn/T/my-script:13:in


I am using IPA characters, such as this one here ʧ which seems to be the culprit (Without that character the script runs fine, although that is not the Unicode character U+00E9 that is listed in the error message, which is just the accented é).

Any help much appreciated!

I try to set default encodings (external and internal), and for good measure use a magic comment at the top of scrivomatic: … crivomatic

#!/usr/bin/env ruby
# encoding: utf-8

Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8

…your script here…

UTF-8 is the Ruby default, but in cases like how Scrivener calls a script, it did seem to help (at least when I had encoding problems with scrivomatic)…

Thank you, Ian, that solved it!