Cache & insert image from URL

I’d like to be able to give Scrivener a URL that generates an image, and have the program download and cache the generated image inside my document package, and then display the cached image inline. As an added bonus, if Scrivener could remember the URL and provide a way for it to be edited/refreshed that would be swell.

Here’s what I’m trying to do: I write mostly technical material, with lots of code excerpts and diagrams and such. I did not purchase Scrivener for this sort of work, but now that I’ve gotten hooked on the program for more casual writing I would sure like to be able to use for technical stuff too.

There are a variety of Web services available that take, for example, a URL with a bunch of query parameters and generate a nice looking chart. Here’s one popular example: http://code.google.com/apis/chart/. And here is a more obscure service that I personally use a lot: http://www.websequencediagrams.com/.

I can, of course, today manually use these tools with my browser to generate images, and then copy the images into my Scrivener document package, and then insert those images into my document text… But it’s a rather clunky workflow compared to what it could be with a little bit of coding.

And with just a little bit more code, URL’s that return arbitrary HTML could be rendered into a WebView and then that could be used to make a cached image… That would be convenient for, say, generating syntax-hilighted source code snippets. (There are services available that do that, too.)

On a personal note, I started with a free license to Scrivener (as an Apple Employee) and have enjoyed using the program so much that I opted to buy it from the Mac App Store anyway. I appreciate the care that’s been taken in choosing the feature set. Keep up the good work!

Thanks for the kind words, and thanks also for buying Scrivener even though you had a free licence - very much appreciated.

To be honest, I’m not quite sure how something like this would be achieved in a straightforward manner, even in code. Scrivener wouldn’t know when to update the image, anyway, so there would always have to be a manual element. However, have you tried using Edit > Insert > Image Linked to File…? This is how you would do it:

  1. Use the online tool and download the image to a file somewhere on disk.

  2. In Scrivener, place the cursor in the text where you want to place the image and then go to Edit > Insert > Image Linked to File… Select the file you created in (1).

Now, whenever you want to update the image, you just do (1) again, replacing the file created the first time with an updated version. (You may need to close and reopen the project to get the image to refresh, though, because it will be cached.)

Thanks again and all the best,
Keith

Hi Keith,

What I had in mind was not to eliminate the manual element… Only to automate it a bit more. [I actually want to choose explicitly when to refresh each image.] If there was, say, a dedicated area in the Binder side-bar for images acquired this way, and Scrivener stored the metadata necessary for the image to be edited/refreshed when necessary, then I could pass along one of my documents to another author with a reasonable expectation that she could keep it up-to-date.

I know Scrivener is not really designed for the technical publishing market. It’s a sadly neglected market, IMO, ever since Adobe abandoned FrameMaker for the Mac.

Hmm, have you ever considered some sort of plug-in or scripting architecture for extending Scrivener?

If I’m honest, this is quite an esoteric request that would require a significant amount of work to get right, I’m afraid, as it would require a completely new type of image document.

This would definitely be nice for the future. AppleScript is on the horizon (even though it has been sitting there for a year or two now), but a full-on API would be a massive job and would need thinking through properly. It’s definitely something I’d be interested in looking at, although probably not until 3.0 or 4.0.

That said, AppleScript might be able to be used for something like this, as long as I expose things properly. You could, for instance, have an AppleScript that takes the path of an image file inside Scrivener, then gets the new file from Safari or wherever, then uses that to overwrite the original path, then tell Scrivener to refresh. So I think this could be made to work once AppleScript support is eventually up and running (the aim is to start on AppleScript for 2.2).

All the best,
Keith