FrontEnd`UnicodeCopy[c : {__Cell}]$unicodeTR =
FrontEnd`FindFileOnPath["UnicodeCharacters.tr",
"PrivatePathsTextResources"] // FrontEndExecute;
$unicodeReplacements :=
Replace[
#[[2]] -> MathLink`CallFrontEnd[
ExportPacket[Cell[CellGroupData[c]], "InputText"]ToExpression[
], {
"\"" <> {s_StringStringReplace[#[[1]], __}{"x" :->
FrontEnd`unicodeCopy@
StringReplace[s":",
char : ("\\[" ~~ WordCharacter ..StartOfString ~~ "]")"0" :->
"\\"}] <> "\""] ToExpression["\""& <>/@
char <> "\""]Rest[
StringSplit@StringSplit[Import[$unicodeTR, "String"], ]"\n"]
}];
FrontEnd`UnicodeCopy[c_Cell]
FrontEnd`UnicodeCopy[c : {__Cell}] :=
Replace[
MathLink`CallFrontEnd[
ExportPacket[cExportPacket[Cell[CellGroupData[c]], "InputText"]
], {
{s_String, __} :>
FrontEnd`unicodeCopy@
StringReplace[s,$unicodeReplacements]
}];
FrontEnd`UnicodeCopy[c_Cell] :=
charReplace[
: ("\\[" ~~MathLink`CallFrontEnd[
WordCharacter .. ~~ "]")ExportPacket[c, :>"InputText"]
], {
ToExpression["\"" <> char{s_String, <>__} "\""]:>
FrontEnd`unicodeCopy@
] StringReplace[s,$unicodeReplacements]
}];
FrontEnd`UnicodeCopy[b_BoxData | _TextData] :=
FrontEnd`UnicodeCopy@Cell[b];
FrontEnd`UnicodeCopy[b_RowBox] :=
FrontEnd`UnicodeCopy@Cell[BoxData@b];
FrontEnd`UnicodeCopy[
nb : _NotebookObject | _FrontEnd`NotebookObject | \
_FrontEnd`SelectedNotebook | _FrontEnd`InputNotebook | \
_FrontEnd`ButtonNotebook | _FrontEnd`EvaluationNotebook | \
_FrontEnd`MessagesNotebook | _FrontEnd`HelpBrowserNotebook | \
_FrontEnd`ClipboardNotebook
] :=
FrontEnd`UnicodeCopy[Evaluate@NotebookRead@nb];
FrontEnd`UnicodeCopy[
nb : _InputNotebook | _EvaluationNotebook | _ClipboardNotebook | \
_ButtonNotebook | _MessagesNotebook | _HelpBrowserNotebook] :=
FrontEnd`UnicodeCopy@Evaluate@nb;
FrontEnd`UnicodeCopy[Optional[Automatic, Automatic]] :=
FrontEnd`UnicodeCopy@InputNotebook[];
FrontEnd`UnicodeCopy[s_String] :=
FrontEnd`unicodeCopy[s];
FrontEnd`UnicodeCopy[e_] :=
FrontEnd`UnicodeCopy[Evaluate@ToString[Unevaluated[e], InputForm]];
FrontEnd`UnicodeCopy~SetAttributes~HoldFirst
(fixed, now, by doing a more selective replacement from UnicodeCharacters.tr
)