Reputation: 37238
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.
Upvotes: 1
Views: 542
Reputation: 47169
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.
Upvotes: 3
Reputation: 611
It sounds like a task that can be done using GUI Scripting using AppleScript.
Upvotes: 1