I thought I'd keep a running tally of what I know about these packets (excluding the obvious ones like `CreatePalettePacket`) just for reference.
#GetFEKernelInit
A large amount of useful functionality is hidden in here which I simply haven't gotten around to investigating. For example there's this:
System`DeclareKnownSymbols[l_] :=
MathLink`CallFrontEnd[
FrontEnd`UpdateKernelSymbolContexts[
$Context, FrontEnd`Private`ResolvedContextPath[],
{{$Context, {}, {}, l, {}}}]
]
which includes that ``FrontEnd`UpdateKernelSymbolContexts`` which had been crashing my copy of Mathematica repeatedly
You can find the file by:
FrontEndExecute@
FrontEnd`FindFileOnPath[
"GetFEKernelInit.tr",
"PrivatePathsTextResources"
]
#Known Packets
###CA`CADumpTriePacket
Seems to extract data from an autocompletion .trie file:
Used like
FrontEndExecute@
CA`CADumpTriePacket[trieFile]
e.g.:
FrontEndExecute@
CA`CADumpTriePacket@First@
FileNames["*.trie",
PacletFind["AutoCompletionData"][[1]]["Location"], Infinity][[1]]
__BEWARE__: If the file isn't a properly formatted trie file this *will* crash your system.
###FindFileOnPath
Used as:
FrontEndExecute@
FrontEnd`FindFileOnPath[
fileName,
path
]
Where `path` is one of:
{
"StyleSheetPath",
"PalettePath",
"PrivatePathsTextResources",
"PrivatePathsSystemResources",
"PrivatePathsAFM",
"PrivatePathsAutoCompletionData",
"PrivatePathsAutoCompletionDataBase",
"PrivatePathsBitmaps",
"PrivatePathsFonts",
"PrivatePathsTranslationData"
}
__Beware__: *if you provide the wrong path it crashes Mathematica instantly*
Note that `path` can be things built from `FileNameJoin`.
###FindAndClickDefaultButton / FindAndClickCancelButton
See [this](https://mathematica.stackexchange.com/a/153096/38205)
These find and click the first button with `"ButtonType" -> "Cancel"` or `"ButtonType" -> "Default"` in the [`Appearance` list](https://mathematica.stackexchange.com/q/134779/38205).
###UpdateKernelSymbolContexts
Used to set symbol coloring in the FE. See [this](https://mathematica.stackexchange.com/a/146279/38205) for more info
###BoxReference
There's a collection of edit mechanisms predicated on `BoxReference*` packets.
These all use ``FE`BoxReference`` (as far as I've seen). The standard usage of this as I've seen looks like:
FE`BoxReference[obj,
{{id}},
FE`SearchStart->startspec
FE`BoxOffset->{offset}
]
Where the options can be dropped.
- `obj` as far as I can tell is a `NotebookObject`, `CellObject`, or `BoxObject`, but you can also get the current spec from from ``FE`Evaluate@FEPrivate`Self[]``
- The `id` searches for `BoxID->id`. It can also be ``FE`Parent[id]``. I don't know what that does.
- The offset should look like ``FE`BoxChild[n]`` or ``FE`BoxParent[n]``.
- The only `SearchStart` I've seen used is `"StartFromBeginning"`.
Here are some usages:
- `BoxReferenceBoxObject` (`BoxReferenceBoxObject[boxref]`)
finds the `BoxObject` for ``FE`BoxReference``
- `BoxReferenceRead` (`BoxReferenceRead[boxref]`)
reads the `BoxObject` for ``FE`BoxReference``
- `BoxReferenceFind` (`BoxReferenceFind[boxref]`)
Selects the `BoxObject` for ``FE`BoxReference``
- `BoxReferenceReplace` (`BoxReferenceReplace[boxref,boxes]`)
Replaces the `BoxObject` for ``FE`BoxReference``
- `BoxReferenceGetOptions` (`BoxReferenceGetOptions[boxref,ops]`?)
I don't actually know how this one works
- `BoxReferenceSetOptions` (`BoxReferenceSetOptions[boxref,ops]`?)
Same here
###ReparseBoxStructurePacket
This one parses a string (as far as I can tell just a string) into a box structure. We can use this to, for example, parse out the string which comes as the last output of `NeedCurrentFrontEndSymbolsPacket` and convert it directly to a box expression:
Cell[
BoxData@
FrontEndExecute[
FrontEnd`ReparseBoxStructurePacket[
FrontEndExecute@FrontEnd`NeedCurrentFrontEndSymbolsPacket[] //
Last]],
"Output"
] // CellPrint
###SimulateKeyPress
This one is weird and I don't really understand it. We'll start with the basic usage:
FrontEndExecute@
FrontEnd`SimulateKeyPress[
keys:_String|_Symbol|_Integer
];
Any `Symbol` passed is simply converted to its fully qualified string form (except for ``System` `` level symbols which simply take their `SymbolName`), the same is true for integers.
The system then simulates a key press for each character in the string. What is odd is that the characters either all come out as if Shift was held or in their lower-case form. That is, the `$FrontEndSession` will either come out as `$FRONTENDSESSION` or as `4frontendsession`. I have been unable to figure out what decides this.
Note that holding a modifier has the same effect as if one was typing.
On top of the weirdness with capitalization, there is a second valid usage form:
FrontEndExecute@
FrontEnd`SimulateKeyPress[
keys:_String|_Symbol|_Integer,
list_List,
___
];
Note that having anything other than a list in the second position does nothing. Oddly, though, I can't figure out what that list is for. Initially I had assumed it was a list of modifier keys. But no set of modifier key strings seems to do anything. In fact I can't find any effect whatsoever of having anything in that list. Note that any argument can follow that list, though. But that second position list is clearly important for something. I just cannot figure out what.
###SimulateMouseMove / SimulateMouseDrag / SimulateMouseClick
`SimulateMouseMove` moves the mouse to a given screen position. Have yet to find a use for it, but it does allow one to play tricks on a user by putting something like:
Dynamic[
FEPacketExecute[
"SimulateMouseMove",
MousePosition[]
],
UpdateInterval -> 0
]
in a notebook. There might be an option for moving to a certain named position, e.g., `Center` but I haven't found it. I just wrote that into a wrapper function.
`SimulateMouseDrag` and `SimulateMouseClick` are similarly obvious:
`SimulateMouseDrag` takes a list of positions `{start, end}` and simulates a mouse drag between the two.
`SimulateMouseClick` just clicks on a position.
A sample usage:
FEPacketExecute["SimulateMouseDrag",
{{1200, 30}, {1200, 50}}];
FEPacketExecute[
"SimulateMouseClick",
{1200, 50}
];
On my Mac, with screen rectangle of `{{4, 1440}, {23, 900}}` this drags a window docked at the top right corner down 20 points.
The click is necessary, I found, to get the OS to recognize the mouse drag.
### AttachedCellParent
This is exactly what you'd expect. Except for 1 big warning. If the [`CellObject`](http://reference.wolfram.com/language/ref/CellObject.html) no longer exists it'll crash Mathematica.
###AttachCell / DetachCell
Found [here](https://mathematica.stackexchange.com/a/99322/38205)
Used as
FrontEndExecute@
FrontEnd`AttachCell[obj: (_CellObject | _BoxObject),
cellExpr_,
{
radialDistanceFromAnchor: (_Integer | _Scaled),
alignment: {Center | Left | Right, Center | Bottom | Top}
},
anchor:
{
Center | Left | Right | _Scaled | _Integer | _Real,
Center | Bottom | Top | _Scaled | _Integer | _Real
},
"ClosingActions"->
{
(
"ParentChanged" | "EvauatorQuit" |
"OutsideMouseClick" | "SelectionDeparture" |
"MouseExit") ...
}
]
From Kuba, when attaching to a notebook using the `"ParentChanged"` setting will crash Mathematica as detailed [here](https://mathematica.stackexchange.com/a/134768/5478)
``FrontEnd`DetachCell`` simply detaches an attached cell.
###AddMenuCommands
Described [here](https://mathematica.stackexchange.com/a/915/38205)
Used as
FrontEndExecute@
FrontEnd`AddMenuCommands[menu,{items}]
where `menu` is the target menu and `items` are `MenuItem`/`Item` expressions or `Delimiter.
See also: https://mathematica.stackexchange.com/a/6227/38205
Which shows how to do this with a `"MenuList*"` menu.
###ResetMenusPacket
This can be used to both reset the menus and set an arbitrary `Menu` structure.
Used as:
FrontEndExecute@
ResetMenusPacket[{menu}]
where `menu` is either a `Menu` expression looking like
Menu["Mathematica", {menu_items_and_submenus}]
or `Automatic` as far as I've discovered. I'm sure there are more use cases but these are the ones I've found.
More info [here](https://mathematica.stackexchange.com/questions/133851/what-are-all-the-possible-menu-edits)
###SelectedObject
``FrontEndExecute@FrontEnd`SelectedObject[nb]`` returns whatever objects are selected in a notebook
###SetMouseAppearance
``FrontEndExecute[FrontEnd`SetMouseAppearance[expr_]]`` sets the mouse appearance
##Obvious but useful
###NotebookGetLayoutInformation
Provides useful information for anyone working with writing papers in mathematica as it gives access to cell sizes and page break info.
###NotebookDynamicToLiteral
Converts the current dynamic selection to its static displayed form.
###ObjectChildren
Provides access to the object hierarchy in a notebook. Particularly useful for getting the boxes in a given cell / box. At the `$FrontEnd` level though this will give you _all_ notebooks which is useful in and of itself.
#Warning
Lots of these crash the system if used improperly. For example a bare ``FrontEnd`UpdateDynamicObjects`` or ``FrontEnd`UpdateDynamicObjectsSynchronous`` also seems to crash the system and passing it an argument doesn't seem to do anything. (Too bad really, I was hoping I could use that as another way to manually update `Dynamic` objects).