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
----------------------------------------------------------------
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
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.
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:
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 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'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.
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.