Forked from reubano/get_title_and_url_from_front_browser.applescript
Created
January 30, 2024 03:18
-
-
Save shredthaGNAR/445c067b1728dce4a0491842dbec3d49 to your computer and use it in GitHub Desktop.
Applescript to get frontmost tab’s url and title of various browsers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This example will return both the URL and title for the frontmost tab of the active browser, separated by a newline. | |
# Keep in mind that by using `using terms from`, we’re basically requiring that referenced browser to be available on the system | |
# (i.e., to use this on "Google Chrome Canary" or "Chromium", "Google Chrome" needs to be installed). | |
# This is required to be able to use a variable in `tell application`. If it is undesirable, the accompanying example should be used instead. | |
tell application "System Events" to set frontApp to name of first process whose frontmost is true | |
set currentTabUrl to "" | |
set currentTabTitle to "" | |
if (frontApp is "Safari") or (frontApp is "Webkit") then | |
using terms from application "Safari" | |
tell application frontApp to set currentTabUrl to URL of front document | |
tell application frontApp to set currentTabTitle to name of front document | |
end using terms from | |
else if (frontApp is "Google Chrome") or (frontApp is "Google Chrome Canary") or (frontApp is "Chromium") then | |
using terms from application "Google Chrome" | |
tell application frontApp to set currentTabUrl to URL of active tab of front window | |
tell application frontApp to set currentTabTitle to title of active tab of front window | |
end using terms from | |
else if frontApp is "Firefox" then | |
tell application "System Events" | |
keystroke "l" using command down | |
keystroke "c" using command down | |
end tell | |
delay 0.5 | |
set currentTabUrl to the clipboard | |
set currentTabTitle to "" | |
end if | |
return currentTabUrl & "\n" & currentTabTitle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment