gpt4 book ai didi

applescript - 在 applescript 中将应用程序设置为最前面

转载 作者:行者123 更新时间:2023-12-05 01:44:56 27 4
gpt4 key购买 nike

我试图找出最前面的应用程序 x 是什么,运行脚本,然后使用 applescript 将 x 设置为最前面的应用程序。

    tell application "System Events"
set frontApp to displayed name of first process whose frontmost is true
set apptemp to frontApp
end tell

[代码在这里]

tell application "System Events"
set frontmost of process whose name is apptemp to true
end tell

尽管此代码不返回任何错误,但它不起作用。我也试过这段代码

tell application "System Events"
set apptemp to application "Google Chrome"
set frontmost of process "Google Chrome" to true
end tell

但同样,虽然没有错误,但它不会工作。

此外,有人请告诉管理员,以便更容易显示代码。我最难在这个网站上显示代码。我必须为每一行代码缩进四个空格,这太疯狂了。

最佳答案

比其他两种方法更好的是使用作为唯一键的包标识符。

tell application "System Events"
set frontAppID to bundle identifier of first process whose frontmost is true
end tell

-- Sample code... can be anything else
activate application "Finder"
delay 3
-- End of sample code

activate application id frontAppID

关于applescript - 在 applescript 中将应用程序设置为最前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44017508/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com