Applescript question
I am trying to get the URL of the current browser window I want to support Safari, Brave, and Google Chrome. I have the following code:
tell application "System Events"
set activeApp to name of first application process whose frontmost is true
display dialog activeApp
if activeApp is in "Brave Browser" or activeApp is in "Google Chrome" or activeApp is in "Safari" then
tell application activeApp to activate
delay 1
tell application "System Events"
-- shift to Addresss bar
key code 37 using {command down}
-- Copy URL
key code 8 using {command down}
-- Escape
key code 53
end tell
else
display dialog ("Sorry, not a supported browser.")
end if
end tell
which works if I hard code the line with
tell application activeApp to activate
to have the name of the particular browser like so
tell application "Google Chrome" to activate
Is there a better way to do this?
Mac mini, macOS 10.15