【问题标题】:AppleScript to target frontmost applicationAppleScript 以最前面的应用程序为目标
【发布时间】:2009-07-18 02:00:39
【问题描述】:

我想对鼠标按钮进行编程以显示/隐藏 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 块使用系统事件来获取脚本的名称并将其隐藏。是否有一种更简单/更快的方法可以在脚本启动之前获取最前面的应用程序的名称? (即激活脚本时处于活动状态的应用程序)

【问题讨论】:

    标签: macos applescript


    【解决方案1】:

    运行时间慢的原因是我将 AppleScript 保存为应用程序。这使得应用程序仅 PPC,因此它必须在 Rosetta 下运行。如果你选择Application Bundle,它将成为一个通用的应用程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-30
      • 1970-01-01
      • 1970-01-01
      • 2012-03-08
      • 2017-08-06
      • 2019-12-18
      相关资源
      最近更新 更多