如何使用AppleScript查找残疾菜单项?
我有一个苹果脚本,可以从所有菜单栏菜单中找到所有菜单项。我已经过滤了每个分离器,所以我只有命令,现在我想找出如何确定哪些菜单项已被禁用。有人知道我该怎么做吗?
更新:
这是我必须获取每个菜单命令的名称的代码。它工作正常,我试图获取在getAppMenuitems中启用的菜单项,但是它也返回了所有菜单项,也丢失了值。
set appName to "Script Editor"
set allMenus to {}
set everything to {}
set onlyEnabled to {}
tell application "System Events" to tell process appName
set allMenus to name of every menu of menu bar 1
end tell
repeat with menuName in allMenus
set the end of everything to strings of getAppMenuItems(appName, menuName, onlyEnabled)
end repeat
on getAppMenuItems(appProcess, appMenus, enabledItems)
tell application "System Events" to tell process appProcess
(*
# Get all menu items
set theItems to every menu item of menu appMenus of menu bar 1
repeat with i from 1 to number of items in theItems
set thisItem to item i of theItems
if thisItem is not enabled then
log ("Item: " & name of thisItem & " is enabled")
set the end of enabledItems to the name of thisItem
end if
end repeat
*)
return name of every menu item of menu appMenus of menu bar 1
end tell
end getAppMenuItems
# From the commented part of the 'getAppMenuItems' function above.
# When that part of the function is uncommented, I just get everything,
# missing values and all
onlyEnabled
# Edit Menu
item 4 of everything
(* Outputs: Half of these items are not enabled
{"Undo", "Redo", "Cut", "Copy", "Paste", "Paste and Match Style", "Paste Reference", "Delete", "Select All", "Complete", "Find", "Spelling and Grammar", "Substitutions", "Transformations", "Speech", "Start Dictation…", "Emoji & Symbols"} *)
I have an AppleScript script that will find all of the menu items from all of the menu bar menus. I've filtered out each separator, so I have just the commands, and now I'd like to find out how to find out which menu items are disabled. Does anybody know how I could do that?
Update:
Here's the code I have to get the names of each menu command. It's working fine, and I tried to get the menu items that were enabled in the getAppMenuItems, but it just returned all the menu items, missing values too.
set appName to "Script Editor"
set allMenus to {}
set everything to {}
set onlyEnabled to {}
tell application "System Events" to tell process appName
set allMenus to name of every menu of menu bar 1
end tell
repeat with menuName in allMenus
set the end of everything to strings of getAppMenuItems(appName, menuName, onlyEnabled)
end repeat
on getAppMenuItems(appProcess, appMenus, enabledItems)
tell application "System Events" to tell process appProcess
(*
# Get all menu items
set theItems to every menu item of menu appMenus of menu bar 1
repeat with i from 1 to number of items in theItems
set thisItem to item i of theItems
if thisItem is not enabled then
log ("Item: " & name of thisItem & " is enabled")
set the end of enabledItems to the name of thisItem
end if
end repeat
*)
return name of every menu item of menu appMenus of menu bar 1
end tell
end getAppMenuItems
# From the commented part of the 'getAppMenuItems' function above.
# When that part of the function is uncommented, I just get everything,
# missing values and all
onlyEnabled
# Edit Menu
item 4 of everything
(* Outputs: Half of these items are not enabled
{"Undo", "Redo", "Cut", "Copy", "Paste", "Paste and Match Style", "Paste Reference", "Delete", "Select All", "Complete", "Find", "Spelling and Grammar", "Substitutions", "Transformations", "Speech", "Start Dictation…", "Emoji & Symbols"} *)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了获取菜单项的属性,您首先需要获取对该菜单项的参考。然后,您需要浏览各种菜单项,并构建符合您条件的列表或记录,以便可以根据需要使用参考。
从评论中,使用菜单层次结构列表单击或获取菜单参考的通用处理程序将达到您的目的,因此这些菜单将是:
In order to get the properties of a menu item, you first need to get a reference to that menu item. You would then need to go through the various menu items and build lists or records of those that meet your criteria, so that the references can be used as needed.
From the comments, general-purpose handlers to click at or get menu references by using a list of the menu hierarchy would serve your purpose, so those would be something like: