Macos 为什么这段苹果脚本将safari打开为隐藏?
我正在构建一个更复杂的applescript,但我想先让基础知识发挥作用Macos 为什么这段苹果脚本将safari打开为隐藏?,macos,safari,applescript,Macos,Safari,Applescript,我正在构建一个更复杂的applescript,但我想先让基础知识发挥作用 tell application "Safari" activate end tell tell application "System Events" tell process "Safari" tell menu bar 1 tell menu bar item "File" tell menu "File"
tell application "Safari"
activate
end tell
tell application "System Events"
tell process "Safari"
tell menu bar 1
tell menu bar item "File"
tell menu "File"
click menu item "New Window"
end tell
end tell
end tell
end tell
end tell
我似乎无法理解的问题是,为什么在运行safari时,它会以隐藏状态打开。在运行脚本时,新窗口不会隐藏 试试这个:
tell application "Safari" to make new document
它也没有为我打开Safari hidden,但是Safari在其他应用程序后面打开,如果它还没有运行,直到我在末尾添加了
将frontmost设置为true
activate application "Safari"
tell application "System Events" to tell process "Safari"
click menu item "New Window" of menu 1 of menu bar item 3 of menu bar 1
set frontmost to true
end tell
您也可以尝试使用重新打开。如果没有可见的窗口,或者例如只有“首选项”窗口可见,或者如果所有默认窗口都最小化,则会打开一个新的默认窗口,并取消其中一个窗口的动画化
tell application "Safari"
activate
reopen
end tell
有了它,并将激活命令移动到最后,它现在可以工作了,谢谢!我可以用不同的方法解决我的问题,但这些建议很好