I would like to copy the address of a hyperlink in Mathematica using the keyboard.
I found code for copying hyperlink addresses in ContextMenus.tr
:
MenuItem["&Copy Address", FrontEndExecute[
{FEPrivate`FrontEndExecute[FrontEnd`CopyToClipboard[
CurrentValue[{ButtonBoxOptions, ButtonData}]]]
}
], MenuEvaluator->None]
but using this to make a keyboard shortcut in KeyEventTranslations.tr as follows doesn't seem to work.
Item[KeyEvent["c", Modifiers -> {Control, Option}], FrontEndExecute[
FrontEnd`CopyToClipboard[ CurrentValue[{ButtonBoxOptions, ButtonData}]]]
]
(KeyEvent["c", Modifiers -> {Control, Option}]
didn't seem to work at all as a shortcut combination, but other combinations that worked for other actions didn't work for copying the hyperlink address.)
One problem is that I'm not sure whether the hyperlink has to be selected or what.
Hyperlink
and then copy and paste it into the text, or one can select some text and create a hyperlink using the menu. In those two cases, Ctrl+c, Ctrl+v either copies a largeTagBox
expression or just the text of the hyperlink, not the address (URI). I now see that one possible solution might be to copy theTagBox
expression and then use another program to replace the clipboard contents with the hyperlink address, which is inside the expression. $\endgroup$MenuItem
you writeFEPrivate`FronEndExecute
while in theKeyEvent
you just writeFrontEndExecute
. Maybe that difference is why the menu item works, but the keyboard shortcut doesn't? $\endgroup$FrontEnd`CopyToClipboard
) with things which don't run in the packet system (CurrentValue
). That would be trivial to work around, but there's a deeper problem, which is thatCurrentValue
will only return the correct thing if exactly the right thing is selected. It works in context menus because the menu system automatically sets the right target. I'm still pondering alternative solutions. $\endgroup$