Jump to content
vitor

[HOW TO] Get frontmost tab’s url and title of various browsers

Recommended Posts

Updated the top post (and the gist) with the JavaScript for Automation (JXA) equivalent. It is superior to the AppleScript code in a number of ways (explained in the comments).

Share this post


Link to post
7 hours ago, cdpath said:

Any update for Firefox? I use Vimperator and send key strokes to get the title and url, but it's not reliable...

 

You’re asking in the wrong place — there’s nothing I can do about it. Ask in their bug tracker.

Share this post


Link to post
22 minutes ago, skeskali said:

Is there a way to update this to include Vivaldi?

 

As a courtesy, you might have posted a link to the browser.

 

To answer your question, the scripts for Chrome/Chromium work with Vivaldi. You just need to change the application name.

Share this post


Link to post

Not too long ago I switched to using Opera as my everyday browser. I really like it (Chromium + native ad blocking + better looking), but missed all the Alfred workflows that get the current URL. 

 

I've already been doing some GUI scripting for other reasons, so the last time by muscle memory I tried to use a "current url" workflow in Opera, I decided to see how hard it would be. Turns out, not hard at all—here's what I added to the script to make it work for Opera: 

 

else if (frontApp = "Opera") then
  tell application "System Events"
	tell application process "Opera"
	  set currentTabUrl to value of text field "Address field" of toolbar 1 of (first window whose subrole is "AXStandardWindow")
	end tell
  end tell

Note: The whole url needs to be showing in the address bar, since that's where this gets it from. So make sure Settings > Browser > "Show full URL in combined search and address bar" is checked. Otherwise, for example, "https://www.google.com/" would just return "www.google.com". Also, Alfred needs to have Accessibility access, but if you're reading this, it most likely already does. ?

 

Hope it helps someone!

Edited by derBingle
fix code indentation

Share this post


Link to post

@derBingle That method seems fine, but I won’t add it to the list because it’s a bit hackish. For it to be added to the gist, it needs to be part of the app’s AppleScript dictionary and have both URL and page title support.

Share this post


Link to post
5 minutes ago, vitor said:

@derBingle That method seems fine, but I won’t add it to the list because it’s a bit hackish. For it to be added to the gist, it needs to be part of the app’s AppleScript dictionary and have both URL and page title support.

 

Understood. ?? I didn't figure you would add it to the gist—it's most definitely an (unavoidable) hack and also subject to change with any changes to Opera. Mainly just sharing for any other Opera switchers like me who want to get back the functionality in their workflows.

Share this post


Link to post

The following Applescript works fine for me with Opera 51.0 on macOS 10.13.3. Perhaps support was added back in? (I have Accessibility enabled in System Preferences, not sure if that matters):

tell application "Opera" to return title of active tab of front window
tell application "Opera" to return URL of active tab of front window

 

Share this post


Link to post

You are correct, @MacFreek. And not only that, they finally show a dictionary. They’ve also changed from the Safari method to the Chrome method.

 

I’ve updated the top post and the gist. Thank you.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...