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.
Hyperlinkand 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 largeTagBoxexpression or just the text of the hyperlink, not the address (URI). I now see that one possible solution might be to copy theTagBoxexpression and then use another program to replace the clipboard contents with the hyperlink address, which is inside the expression. – Andrew Mar 07 '12 at 14:20MenuItemyou writeFEPrivate`FronEndExecutewhile in theKeyEventyou just writeFrontEndExecute. Maybe that difference is why the menu item works, but the keyboard shortcut doesn't? – celtschk Mar 08 '12 at 17:17FrontEnd`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 thatCurrentValuewill 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. – John Fultz Mar 09 '12 at 07:55