AppleScript目标前置应用程序

8

我想编程我的鼠标按钮来显示/隐藏Finder。我编写了以下的AppleScript并将其绑定到我的鼠标按钮:

tell application "System Events"
    --When this script is run,
    --  the frontmost application will be this script itself
    --Get the name of this script as it is running and hide it,
    --  so that the previous frontmost application is in front again
    set theName to name of the first process whose frontmost is true
    set visible of process theName to false

    set theName to name of the first process whose frontmost is true
end tell

if theName is "Finder" then

    tell application "System Events"
        set visible of process "Finder" to false
    end tell


else

    tell application "Finder"
        activate
    end tell

end if

这样可以工作,但速度相当慢。运行需要大约2秒钟。
我希望它能更快。第一个tell块使用System Events获取脚本的名称并隐藏它。有没有一种更简单/更快的方法在脚本开始之前获取最前面应用程序的名称?(即在激活脚本时处于活动状态的应用程序)

1个回答

5
慢运行时间的原因是我将AppleScript保存为应用程序。这使得该应用程序仅支持PPC,因此必须在Rosetta下运行。如果选择Application Bundle,则会生成通用应用程序。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接