This is my dock menu:
I would like to programmatically click that button "Show Most Recent Window". Can this programmatically be done using Cocoa or CoreFoundation?
I know the PID the dock item is associated with.
There are many ways to achieve this, although generally you can easily set an AppleScript
or oascript
that can handle this. Basically it involves using AXRaise
, which essentially calls on the function to raise the frontmost window of the application specified.
Code:
set mostrecentWindow to "mostrecentWindow"
set theApplication to "Safari"
tell application "System Events"
if exists process theApplication then
--raise frontmost window
tell process theApplication
set frontmost to true
perform action "AXRaise" of (windows whose title is mostrecentWindow)
end tell
else if not (exists process theApplication) then
--display alert
display alert "Warning: process " & theApplication & " is not running"
end if
end tell
The above example checks whether or not the process Safari is running, and if it is then raise it's most recent (or frontmost) window to the foreground; otherwise show a warning that the process is not running.
这听起来像是可以使用AppleScript使用GUI 脚本来完成的任务。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.