Is there a way to attach a file into a notebook and open it later with, for instance, a double click (or another action button)?
In Mathematica windows version, the insert menu has the "object..." entry and I can indeed embed an object into my notebook. But then, I don't know how to exploit it in an attachment kind of way. For instance, in MS Word, if we "insert an object", we can then open it by double clicking its icon: windows opens the file with its predefined application.
For the purpose of the discussion, let’s suppose I want to attach a pdf file.
If this functionality isn't native on Mathematica, probably a technique based on this post can be used, with an intermediate step of export to a temporary folder, and then a
Run kind of command...
I can also imagine a
Dynamic interface, with a list of attached files (whose internal data/content is “kept” by a
DynamicModule internal variable), and four buttons: add, delete, export and open. Since a
Dynamic cell can be easily copied from a notebook to another, I could easily use this small embedding app on different notebooks.
There’s probably another button that would be useful: import. This would make the file content available, as a string, on a global context variable, or at least export the file to a temporary folder, and make its path available on a global context variable.
(if you go the "dynamic app" way, please consider, from the beginning, app conflicts if two apps are added to the same notebook; and a more tricky, or probably impossible task, to make some of its functionality work on the Player)
EDIT - 2014-01-12
(there was an error with the OPEN, that has now been corrected)
Code and example file: download here
Any help on making it better is appreciated, specially in the domain of the compression ratio and safety (currently using GZIP).
Future developments (if anyone can help):
- attach the notebook itself without passing through files (poor man self-included versioning)
- attach a Save of a specific variable/definition or a list of them, without passing through files.
- attach a Save of the entire session, to record current state of sessions (kind of persistent memory)
- load stored Saves (with the option of overlaying the existing memory, substitute completely the existing memory (clearing other definitions), adding definitions with an indexed definition name or or an indexed context, so to allow comparisons...)
- export recorded files to variables, so to work on them (ImportString, etc) without passing through files
- and any other crazy infeasible idea...
EDIT - 2014-02-09
It is now possible to save the definitions of the current context. It is very rough, and I would greatly appreciate some help to improve it. Things that are not great:
it stores its own definition, which could probably be avoidable
something better should be thought for the problem of creating a new context registry when an old one is opened
why only the current context, and not a checkbox tree list where one checks contexts and/or definitions that would like to be stored
no warning for very large content being saved
The file can be downloaded here