我想编写鼠标按钮来显示/隐藏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获取脚本的名称并将其隐藏。是否有更容易/更快的方法来获取最前面的应用程序名称之前脚本启动? (即激活脚本时激活的应用程序)
答案 0 :(得分:5)
运行缓慢的原因是我将AppleScript保存为应用程序。这使应用程序仅限PPC,因此必须在Rosetta下运行。如果您选择Application Bundle,它将成为一个通用应用程序。