I hope I am asking the question in the right way:
I am writing a script that will be saved as a script application so that I can attach a shortcut keys to it either by BTT or through Automator services. One handler within the script is to extract the URL address of the frontmost browser if I am calling the script while I am using the browser.
The problem: since the script itself is already an app, so the frontmost application will always be the script instead of the browser while I am using the browser. BTT offers an option to run the script application in background (so the handler will work) but it seems that automator>quick action doesn’t have such option?
I hope someone can suggest a solution for this?
Thank you very much!
on getWebLink() -- this line will always return the name of the script application tell application "System Events" to set theApp to name of first application process whose frontmost is true if "Safari" is in theApp then tell application "Safari" set theWebURL to URL of front document set theWebName to name of front document return "[Source: " & theWebName & "](" & theWebURL & ")" end tell else if "Chrome" is in theApp then tell application "Google Chrome" set theWebURL to URL of active tab of front window set theWebName to title of active tab of front window return "[Source: " & theWebName & "](" & theWebURL & ")" & return & return end tell else return "" end if end getWebLink