# Tag Info

## Hot answers tagged clipboard

22

Since a native method is not forthcoming, I shall post my file based circumvention, for Windows. You will need to have this utility in the command path (it apparently is stock with Windows 7). copyUnicode[expr_] := Run["clip <", Export["$Clipboard.temp", ToString[expr, InputForm], "Text", CharacterEncoding -> "Unicode"] ]; Usage: expr ... 16 Declaration: This method for Windows is based on the .NET code from Todd Gayley's this wonderful answer. My .NET knowledge is absolutely ZERO, all credit goes to Todd. Code: The main idea is to extract the "Input"-style code string, convert it to the UTF-16 little endian form, which is the standard byte order in Windows, feed the bytes to system clipboard ... 12 Here are two functions that'll do what you need. putClipboardImage[img_Image] := Module[{nb}, nb = CreateDocument[{}, Visible -> False, WindowSelected -> False]; NotebookWrite[nb, Cell[BoxData@ToBoxes@Image[img, Magnification -> 1]]]; SelectionMove[nb, All, CellContents]; FrontEndTokenExecute[nb, "CopySpecial", "MGF"]; ... 11 Edit 2: A new version of the Mac solution with button is listed below Fixed problem with pasting into textarea In some applications on Mac, copying as Unicode from Mathematica already works without having to do any postprocessing. However, it doesn't work in textarea fields in web browsers. Nevertheless, if you're willing to do a few additional mouse ... 11 Paste is a command that, as a side-effect, inserts the contents of the clipboard into the current notebook selection. The return value is always Null, which means that Paste cannot be used for our purpose without some awkward notebook manipulation. There is an undocumented way to access the clipboard: ClipboardNotebook. NotebookGet[ClipboardNotebook[]] ... 7 I use a small web application for when there are too many to convert by hand. 7 Here's a version that doesn't require a temporary file. Linux (needs xclip) SetAttributes[copyUnicode, HoldAll]; copyUnicode[expr_] := With[{ stream = OpenWrite["!xclip -in -selection clipboard", CharacterEncoding -> "UTF-8"] }, WriteString[stream, ToString[Unevaluated@expr, InputForm]]; Close@stream; ]; Example: executing the cell ... 6 Here is a function that copies a Unicode string to the clipboard using JLink: Needs["JLink"]; InstallJava[]; LoadJavaClass["java.awt.Toolkit", AllowShortContext -> False]; uniclip[s_String] := JavaBlock[ javaawtToolkitgetDefaultToolkit[]@getSystemClipboard[]@setContents[#, #]& @ JavaNew["java.awt.datatransfer.StringSelection", s] ... 5 For example: Binarize /@ ToExpression@ Cases[NotebookGet[ClipboardNotebook[]], BoxData[_], Infinity] 4 Here's how to add a permanent menu item and keyboard shortcut for Silvia's solution. (This can be easily adapted to Jens' solution for Mac OS.) 1. Add Package Copy Silvia's first code block that starts with Needs["NETLink`"] to a file and save it as UniCodeCopy.m in one of the directories included in$Path. 2. Initialize the Front End Save the ...

3

If you look at the internal expression of the cell containing the image, you'll find that it also uses the compressed form. However, the usual trick of Cell@BoxData@ToBoxes... doesn't seem to work here, as that only gives us the RawArray representation. This gives us a hint at a possible way of retrieving the compressed representation without having to build ...

2

This isn't exactly what you want, but if you File > Print > Save as PDF then the content will appear correctly. It's only Export where it doesn't appear.

1

This is a possible solution that I came up with after looking at another answer by @Ragfield: Encoding format used by GraphicsData? I had to modify the function decodePICT in that post to cut out the leading zero bytes: DecodePDF[data_String] := Module[{slash, backslash, zero, LF, CR, decode, codes, len, i}, {slash, backslash, zero, LF, CR} = ...

1

This works for me: boxes = ToBoxes@Graphics@Raster[RandomReal[{0, 1}, {5, 5}]] (* ==> GraphicsBox[ RasterBox[{{0.0429951, 0.153342, 0.815801, 0.825589, 0.178414}, {0.732659, 0.659418, 0.871481, 0.644735, 0.54453}, {0.499096, 0.328874, 0.40405, 0.436912, 0.0551782}, {0.824125, 0.889256, 0.249706, 0.562126, 0.408294}, {0.612762, ...

Only top voted, non community-wiki answers of a minimum length are eligible