What i said was that the code that you supplied with that hard to read listing does not lead to the expected result of swapping words.
I would use 2 actions of the type "Format value" for the artistsort field:
Format string: $regexp(%artist%,'(.*) (.*) (.*)','$2, $3 $1')
and the next:
Format string: $regexp(%artist%,'(.*?) (.*)','$2, $1')
Edit: why was it necessary to import the actions from Windows as you got a solution for the Mac already: