Tôi muốn lập trình nút chuột để hiển thị/ẩn Trình tìm kiếm. Tôi đã viết AppleScript sau và giới hạn nó với nút chuột của tôi:AppleScript để nhắm mục tiêu ứng dụng phía trước
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
Công trình này, nhưng khá chậm. Mất khoảng 2 giây để chạy.
Tôi muốn nó nhanh hơn. Khối lệnh đầu tiên sử dụng System Events để lấy tên của tập lệnh và ẩn nó. Có cách nào dễ dàng hơn/nhanh hơn để lấy tên của ứng dụng phía trước trước khi tập lệnh bắt đầu không? (ví dụ: ứng dụng đã hoạt động khi tập lệnh được kích hoạt)