9

如何检测前端令牌是否可以执行?或者,如何检测前端令牌是否无法执行?

示例:如果未选择任何内容,则编辑 -> 复制命令不可用。 FrontEndTokenExecute["Copy"]在这种情况下只会发出哔哔声,但它没有(程序化)指示它失败了。

4

1 回答 1

5

我找到了一种方法来处理你的第二个问题,但它并不优雅:

  1. Preferences > Interface > Message and Warning actions次要用户界面警告设置为Beep和 Print to Console
  2. 确保消息窗口中至少有一条错误消息
  3. 获取消息窗口笔记本的句柄(使用Notebooks[]左右)
  4. 使用存储消息笔记本中的最后一个单元格 NotebookGet[NotebookObject[FrontEndObject[LinkObject["55d_shm", 1, 1]], 1]]/. Notebook[{___, Cell[a___]}, ___] :> Cell[a](当然,您的句柄看起来会有所不同)
  5. 您的电话:FrontEndTokenExecute["Copy"]
  6. 获取最后一条错误消息并检查它是否与步骤 4 中存储的错误消息不同。
  7. 错误单元格看起来像Cell["You tried to edit a cell that is not editable. You can make the \ cell editable by choosing Cell Editable in the Cell Properties \ submenu.", "Message", "Message", "MSG", PageWidth -> WindowWidth, ShowCellLabel -> True, CellChangeTimes -> {3.534442831*10^9}, CellTags -> "cantEditLockedCell"]
  8. 采取适当的行动
于 2012-01-01T22:03:08.167 回答