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

I use this : https://github.com/flipxfx/sVim

Which accomplishes the same thing I believe. Nowhere though does it actually give me what I want though :frowning: What @DanThomas created with this macro is pretty much what I was looking for, only missing this one thing to make it incredibly robust.

Thanks for the link! Some very clever extensions there, though not all compatible with current Safari.

(That refutes my believe that I’ve already visited every web page :astonished:)

Though sometimes it seems that way, doesn't it?

1 Like

Hey Folks,

Small edit in my post with the script:

“Given a domain filter it will move to the first tab whose URL contains that domain.”

This means the URL of the given tab.

NOT a URL that is contained in the web page of the given tab.

-Chris

1 Like

Hey @DanThomas,

I really appreciate the utility of this amazing script. I use it daily. But would it be possible to extend it as I have mentioned above where it would let users cycle through active tabs that all fall into the matching of the parameter. So if I have a macro like this :

And have multiple stack overflow pages, I wish I could jump between them with each macro trigger. Or if I had multiple GitHub repositories, it would do the same.

Would save me a lot of time and be so so useful.

Thank you and I hope you will consider adding such support.

I suppose it’s possible, but I won’t be doing it any time in the near future. Sorry!

Hey Nikita,

The AppleScript I posted above does this...

-Chris

1 Like

Oh hey Chris,

Let me try it again. Last time I remember trying it there was something off with it.

Hey Chris,

For it to work, do I replace his part of Dan's sub macro with your applescript?

Because when I do that, I get an error.

No, my script is stand-alone.

-Chris

1 Like

Oh my, this is exactly what I was looking for.

Except for one thing. It doesn’t initially open the web page if no web page of the url exists. With that it would be complete.

Another daily script I use from you. :slight_smile:

I am actually extremely curious what your workflow is like given just how much you know about automation. Never had a thought of writing a blog? :slight_smile:

I would certainly read it.

Hey Nikita,

Easily fixed – search the script for “new”.

-Chris

------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/01/06 19:04
# dMod: 2017/03/06 17:40
# Appl: Safari
# Task: Serially switch between tabs having the same domain (or other filter text in the URL) in the front window.
#     : 2017/03/06 – Now opens a new tab if the urlFilterText isn't found.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Safari, @Serially, @Switch, @Tabs, @Domain, @Filter, @Front, @Window
# Vers: 2.0
------------------------------------------------------------------------------

set urlFilterText to "forum.keyboardmaestro.com"
set urlToFetch to "https://forum.keyboardmaestro.com"

tell application "Safari"
   tell front window
      set filteredTabIndexList to index of tabs where its URL contains urlFilterText
      set currentTabIndex to index of current tab
      
      if filteredTabIndexList = {} then -- New
         
         set tabURL to URL of current tab
         
         try

            tabURL -- will be undefined if the page is blank and throw an error

            # If the above line does NOT error:
            make new tab at end of tabs with properties {URL:urlToFetch}
            set current tab to last tab

         on error

            # Tab is blank, so we'll just use it.
            set its current tab's URL to urlToFetch

         end try
         
         return
         
      end if
      
      if currentTabIndex is in filteredTabIndexList and currentTabIndex ≠ (last item of filteredTabIndexList) then
         set listItemOffset to getListItemOffset(filteredTabIndexList, currentTabIndex) of me
         set current tab to tab (item (listItemOffset + 1) of filteredTabIndexList)
      else
         set current tab to tab (item 1 of filteredTabIndexList)
      end if
      
   end tell
end tell

------------------------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------------------------
on getListItemOffset(theList, listItemValue)
   if listItemValue is not in theList then error "getListItemOffset():  “listItemValue” is not in “theList”!"
   repeat with listItemNum from 1 to (length of theList)
      if (item listItemNum of theList) = listItemValue then
         return listItemNum
      end if
   end repeat
end getListItemOffset
------------------------------------------------------------------------------
2 Likes

This would save me so much time. Thank you a lot Chris. How about that blog? :slight_smile:

Yes. I just need the time and oomph.

-Chris

1 Like

Isn’t that what we’re all doing here? Saving time. :slight_smile:

Starting getting this error every time I try call the macro :

Is the macro :

Never got it before and not sure what to do.

Thank you for any help.

I have the same error on Safari 10.1
Its still working ok on Safari 10.0.3

Has anyone solved this “Can’t convert types” error? I’d really miss this Plugin, it worked great when it worked.

Also, is it limited to 10 or does it continue with the newer versions of Safari.

Thanks

There is another pretty easy way to reload Safari tabs

You just need to specify a tab position 1,2,3...

The script will refresh a specified tab in the background