Hello
You may try an Automator service with a Run Shell Script action as follows.
0) Automator service
- Service receives selected [text] in [any application]
- [x] replace selected text
1) Run shell Script action
- Shell: /usr/bin/ruby
- Pass input: as argument
- Code: as follows
ARGV.map { |a| a.dup }.each do |a|
if ( d = a[/\015\012|\015|\012/] )
e = a.chomp!(d) ? d : ''
print a.split(d, -1).shuffle.join(d), e
else
print a.split(' ').shuffle.join(' ')
end
end
Resulting workflow will look something like this:

The service will -
a) shuffle lines if multiple lines are selected; or
b) shuffle words (delimited by white spaces) if single line is selected.
In case of a), trailing line-ending character is preserved as the last character. And in case of b), delimiting white spaces are reduced to single space.
Regards,
H