These days I often copy urls from Internet Explorer's address bar. When I paste the url into a Mathematica cell it is neither a string nor a expression.


I always manually add " " to get


Another method is to use InputString[]

sometimes, I don't like the pop-up dialog.

Is there any more lazy way to make


successful, maybe by using a button, or InputField, or other setting, or some styled-cell?


3 Answers 3


You can create styled cells with a custom CellEvaluationFunction to do this (similar to this R cell answer). As a simple example:

URLCell[] := Module[{},
    CellPrint@Cell[TextData[""], "Program", 
        Evaluatable -> True, 
        CellEvaluationFunction -> (Import@First@FrontEndExecute[FrontEnd`ExportPacket[Cell[#], "InputText"]] &), 
        CellGroupingRules -> "InputGrouping"
    SelectionMove[EvaluationNotebook[], All, EvaluationCell];
    SelectionMove[EvaluationNotebook[], Next, CellContents]

Now call URLCell[] and it should replace that line with a cell where you can just paste the URL directly and evaluate:

enter image description here

You can reuse the same cell, or if you want to use it in a stylesheet, see the linked answer above.

  • $\begingroup$ ahh, interesting, cool.thanks $\endgroup$ Commented May 23, 2013 at 2:46
  • 2
    $\begingroup$ Looks more complicated than just type two double quotes. Not your fault, though +1. $\endgroup$ Commented May 23, 2013 at 19:07

Why not just make a palette button? It's simpler and more reusable than a custom cell style.

Simple way:


More complicated way:

Button["Paste URL Import", 
 Module[{data, strip}, 
  data = NotebookGet[ClipboardNotebook[]][[1, 1, 1]];
  If[Head[data] === String, 
   NotebookWrite[InputNotebook[], "Import[\"" <> data <> "\"]"]]]]

You can wrap these in a CreatePalette if you wish, which will create palette. Then you ca use Palettes -> Install Palette... to install it for permanent use.

If you want to paste tabular data from a website, I recommend that you use Firefox (which allows you to Control-select an arbitrary rectangular part of a table), and then use the tool here to paste it. Search for "tabular" on that page.

  • $\begingroup$ yeahp, I forgot the Clipboard function, a good way. Ctrl+V should be instead by ButtonClick. $\endgroup$ Commented May 24, 2013 at 2:52

Good for you folks for doing it in Mathematica! But there is a good argument for making this kind of improvement to your system at a lower, system-wide level (no matter what XKCD says). If, for example, you're constantly wanting to insert the URL of the current web page into another document, it makes sense (to me) to make this happen for all applications that you work with (text editors, email, forms on web pages, and so on).

Naturally the solution will be platform specific - on Mac OS I use either Keyboard Maestro or TextExpander. I'm sure there are many more solutions for Windows. Also, the solution will probably involve some scripting - AppleScript, Perl, Python, or Ruby for Mac OS.

enter image description here

You can imagine how much easier writing is when you don't have to switch between applications, and when you can use any application in the same way.

(Sorry for large-ish GIF. It would be cool to embed YouTube movies...:)

  • $\begingroup$ well, seems i don't understand this answer clearly. I have a thought is that there is an dynamic variable q which monitor the clipboard. $\endgroup$ Commented May 24, 2013 at 3:57
  • $\begingroup$ @HyperGroups No, this is a non-Mathematica solution that works in any application - and just happens to work in Mathematica too. $\endgroup$
    – cormullion
    Commented May 24, 2013 at 6:35
  • $\begingroup$ May I ask how did you record this animation? $\endgroup$
    – shrx
    Commented Jun 12, 2013 at 19:01
  • $\begingroup$ @shrx I think this was either QuickTime or Screeny, then resampled in Mathematica (of course!)... $\endgroup$
    – cormullion
    Commented Jun 12, 2013 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.