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:
https://literatureandlatte.com/web/forum/viewtopic.php?f=2&t=52114

In that thread it was already mentioned that

The solution suggested was to add the line

ARGF.set_encoding(Encoding::UTF_8) 

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

[/code]

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:

github.com/iandol/scrivomatic/b … 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!