MacOS – Getting process currently open in full screen mode

applescriptautomationmacos

I have a simple AppleScript that works when initiated from an application that is not in full screen mode but does not work when in it's in full screen mode:

#!/usr/bin/osascript

tell application "System Events"
  set fp to (path to frontmost application) as text
end tell

tell application "Safari"
  <snip>
end tell

activate application fp

When not in full screen mode, instead of the window of the application in full screen mode getting activated, another non-full screen window in the same application is activated. How do I tell applescript to activate the original window in full screen mode?

Best Answer

Found something that works. Not sure if it's the best approach.

#!/usr/bin/osascript

tell application "iTerm2"
  set fp to name of current window
end tell


tell application "Safari"
  <snip>
end tell

tell application "iTerm2"
  activate
end tell

tell application "System Events" to tell process "iTerm2"
    click menu item fp of menu of menu bar item "Window" of menu bar 0
end tell