UI自动化,appleScript非菜单项的键盘快捷键预览?
我正在尝试创建一个用于预览的快捷键操作,即绘制和绘制。但是,它们是非菜单项,这意味着无法在系统首选项中完成。我看到有人从中完成,这是可能的,但当我尝试单独执行时,这是我的代码,请帮助我完成此操作。以下是行动 这就是我现在面临的错误 经过一些研究,UI/accessibility inspector有帮助吗 理想情况下,当所有的酒吧都隐藏起来时,试着让它工作, 但如果不可能的话。我们是否可以在显示标记栏的情况下使其工作。如下UI自动化,appleScript非菜单项的键盘快捷键预览?,applescript,ui-automation,Applescript,Ui Automation,我正在尝试创建一个用于预览的快捷键操作,即绘制和绘制。但是,它们是非菜单项,这意味着无法在系统首选项中完成。我看到有人从中完成,这是可能的,但当我尝试单独执行时,这是我的代码,请帮助我完成此操作。以下是行动 这就是我现在面临的错误 经过一些研究,UI/accessibility inspector有帮助吗 理想情况下,当所有的酒吧都隐藏起来时,试着让它工作, 但如果不可能的话。我们是否可以在显示标记栏的情况下使其工作。如下 我使用最新版本的macOS Mojave完成这项工作 tell appl
我使用最新版本的macOS Mojave完成这项工作
tell application "Preview" to activate
repeat while application "Preview" is not running
delay 0.2
end repeat
tell application "System Events"
try
click menu item "Show Markup Toolbar" of menu 1 of menu bar item "View" of menu bar 1 of application process "Preview"
end try
delay 0.5
try
click menu item "Show Toolbar" of menu 1 of menu bar item "View" of menu bar 1 of application process "Preview"
end try
delay 0.5
repeat while not (exists of toolbar 1 of window 1 of application process "Preview")
delay 0.2
end repeat
set description2 to a reference to every checkbox of toolbar 1 of window 1 of application process "Preview"
set theCheckboxes to description of description2
if item 1 of theCheckboxes is "Draw" then
set checkBoxDraw to 1
else
set checkBoxDraw to 2
end if
if item 1 of theCheckboxes is "Sketch" then
set checkBoxSketch to 1
else
set checkBoxSketch to 2
end if
delay 1
-- Below, insert either checkBoxSketch for "Sketch" or checkBoxDraw for "Draw"
click checkbox checkBoxDraw of toolbar 1 of window 1 of application process "Preview"
end tell
-- without these next following lines, the toolbar "Draw" or "Sketch" do not appear to be selected
tell application "Preview" to tell window 1
set visible to false
set visible to true
end tell
delay 3
我们应该如何系统地定位UI元素?有没有一种方法可以列出应用程序的所有UI元素?请在发布布局时再试一次,我忘记了默认布局,否则,我会自己尝试。或者您可以发布适合您的布局,在匹配工作布局后将再次运行。@ch1zpink,感谢您更新代码。也许我从一开始就做错了。你的代码运行没有错误,但仍然没有完成任务,选择绘图作为当前工具。发布了一个全新的版本。。尝试在脚本编辑器应用程序中运行该命令。。。。想知道你是否仍然会出错
tell application "Preview" to activate
repeat while application "Preview" is not running
delay 0.2
end repeat
tell application "System Events"
try
click menu item "Show Markup Toolbar" of menu 1 of menu bar item "View" of menu bar 1 of application process "Preview"
end try
delay 0.5
try
click menu item "Show Toolbar" of menu 1 of menu bar item "View" of menu bar 1 of application process "Preview"
end try
delay 0.5
repeat while not (exists of toolbar 1 of window 1 of application process "Preview")
delay 0.2
end repeat
set description2 to a reference to every checkbox of toolbar 1 of window 1 of application process "Preview"
set theCheckboxes to description of description2
if item 1 of theCheckboxes is "Draw" then
set checkBoxDraw to 1
else
set checkBoxDraw to 2
end if
if item 1 of theCheckboxes is "Sketch" then
set checkBoxSketch to 1
else
set checkBoxSketch to 2
end if
delay 1
-- Below, insert either checkBoxSketch for "Sketch" or checkBoxDraw for "Draw"
click checkbox checkBoxDraw of toolbar 1 of window 1 of application process "Preview"
end tell
-- without these next following lines, the toolbar "Draw" or "Sketch" do not appear to be selected
tell application "Preview" to tell window 1
set visible to false
set visible to true
end tell
delay 3