MACRO or PLUGIN: Open or Refresh a URL in a Tab (Safari & Chrome)

Hey Kirill,

You can also do something like this.

This script reloads every tab in the front Safari window, but it can easily be adapted to work with a specific tab in a specific window.

-Chris

----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2011/08/09 20:33
# dMod: 2015/11/14 16:46
# Appl: Safari
# Task: Reload Every Tab in front window.
# Libs: ELb
# Osax: None
# Tags: @Applescript, @Safari, @Reload, @Tabs, @Front, @Window
----------------------------------------------------------------

tell application "Safari"
   
   set tabList to tabs of front window
   
   repeat with theTab in tabList
      tell theTab to do JavaScript "location.reload(true)"
   end repeat
   
end tell

----------------------------------------------------------------
1 Like

Agreed. Still works for Chrome, but not safari. And I'm on 12.0. A huge bummer, as I loved this macro!

Great plugin/macro! Unfortunately, I'm having the same problem with this, a simpler version I tried to make for myself, as well as @JMichaelTX 's from here.

In all of these, the correct tab is selected but the chrome window is not set to frontmost. In other words, if I have only one chrome window open everything works perfectly but if I have 2 chrome windows open and the opposite window is currently focused, "AXRaise" is not working at all to switch to the window with the desired tab.

Mac version: 10.14
Chrome version: 72.0.3626.121
KM Version: 8.2.4

EDIT: taking a closer look the following Applescript works fine for me with "Safari", but not at all with "Google Chrome"

tell application "System Events"
	tell application process "Google Chrome"
		tell (window 2) to perform action "AXRaise"
	end tell
end tell

Re the "can't convert types" error that stops this working with safari: I think I have fixed it, but I don't really understand the fix :slight_smile:
Replacing the line:
var result = _app.windows.whose(_not: [{document: null}]});
with:
var result = _app.windows
removes the error. It may have been required on an older version of safari? I've tested it with multiple safari windows, blank tabs, etc, and it seems robust.

I've attached my patched version here.

MACRO - Open or Refresh a URL in a Tab (Sub-Macro).v1.1a.kmmacros (1.7 KB)

2 Likes

THANK YOU FOR THIS! So great for bringing my CRM web app to the front.

Hey! Thanks for this awesome script! I use Microsoft Edge. How do I add it in the macro?

I tried to Delete the Macro from the Kayboard Maestro and now I'm getting this error. Can anyone please help?image

This works with Microsoft Edge with two edits.

  1. After you load the macro into KM, select the macro and expand the third action, "Parse Parameter into [...]".
  1. Expand "Do the work".

That's it for edits.

Remember put "Microsoft Edge|" as the first part of the parameter passed to the macro. An example:

1 Like

Ditto for Brave Browser! Thanks!

This works beautifully on the Stream Deck using KMLink, for those interested.

1 Like

@DanThomas, thanks for sharing this fantastic macro.

@John_C, thanks for the tip to regarding the Can't convert types error.

@slamm & @fearoffish, thanks for sharing the Microsoft Edge and Brave Browser information.


For those using the macro...

I observed that I need to include a trailing slash if I'm specifying a URL that ends with the domain, e.g.,

https://forum.keyboardmaestro.com/

If the slash is excluded, a new tab is opened even though it seems there is an exact match.

Contrastingly, when specifying a URL that does not end with the domain, the URL specification is as expected, e.g.,

https://wiki.keyboardmaestro.com/manual/Single_Page_Version#Tour
1 Like

Upon further testing today with Safari v16.0 (18614.1.25.11.1), Ventura developer beta 5 (even after making the change @John_C suggested), I found that if Safari is open but there are no open windows, calling this macro generates:

This can be avoided by adding the following group of actions before calling the macro.

Group.kmactions (5.2 KB)

Keyboard Maestro Export

Hi All,

I just found the Orion browser and it's exciting, especially as both the Mac + iOS versions take Chrome and Firefox extensions (though not all work yet). It also has an amazing implementation of vertical tabs: it INDENTS tabs opened from given page under the tab for that page, so you end up with a "heirarchical outline" of tabs organized by which tabs came from which pages. This not only organizes a sea of tabs into something that makes sense, but lets you see how many pages are left to go through for a given search if you've Cmd+clicked a bunch of links! It's pretty great seeing progress and knowing how many results are left as you Cmd+W (close) one tab after another...rather than having to wait for the search page to show again to find out!

Anyway, I write this because I'm trying to make this Macro work with Orion (I had gotten Brave to work in the past), but am getting the message:

I tried adding the steps to bring browser to front recommended by @_jims (changing Safari to Orion) but didn't seem to help.

Hoping for any assistance. Thanks!

@DanThomas Would be nice to have option to select other browser besides safari and chrome. For example Orion.

1 Like

Perhaps, but don't hold your breath. :slight_smile:

Knowing your drive and expertise I almost dare too :sweat_smile:

1 Like

I got this running, even managed to fix the "Can't convert types" error, even though I didn't even know which file to change it in (somehow found the "Action.scpt" file and changed the first instance of it in there, seems to have worked).

But I'd really love for this to open a new window instead of a new tab in case the website is not already open. Is it possible to do that?

I assume it's possible, but I ain't gonna do it. :grinning:

1 Like

I'm having an issue where the plugin doesn't seem to activate the right tab.
Scenerio:

I have 2 chrome tabs open side by side. Left tab is URL#1, Right Tab is URL #2. I have the plugin set to "Match Start" and put in URL#1 in the field. When I run the macro URL #2 is chosen, even though URL#2 is totally different from URL#1.

Any ideas?

Nyet.

And no one is likely to, unless you provide an actual test case for folks to try out.

1 Like

Hello Dan,
I am a Keyboard Maestro novice who just got started a week ago. I was amazed to find that you had developed exactly the kind of macro I was hoping existed. And you did that almost 6 years ago! Thank you so much.

I did however run into a small glitch when I ran it. It put out the message
" Error: Can't convert types" in a separate window.

When Safari wasn't even running, it started Safari and then failed with the error. With Safari running in the background, I got this error right away.

I am not a programmer and have no clue as to how Javascripts (or other scripts) work. Am I doing something wrong? Is there any more information I can provide you to help figure out why it is failing? I hope you can help me.

Pathy