Friday, February 17, 2023

Homecoming for Mastodon 2.0

Jeff Johnson:

As before, when you’re viewing a Mastodon page in another instance, clicking the extension icon in Safari’s toolbar opens that page in your own instance. On the other hand, when you’re viewing a Mastodon page in your own instance, clicking the extension icon in Safari’s toolbar opens that page in the original instance.

[…]

Returning to motivation, why would you want to open a Mastodon page in its original instance when you’re already reading it in your instance? The answer is that a Mastodon instance is a kind of island. It can only show you the data stored locally. Unlike a centralized network such as Twitter or Facebook, Mastodon is decentralized and distributed: no individual instance has a copy of all the data encompassing the federation of Mastodon, only a subset of the data. Every Mastodon instance has gaps in its data, blind spots. An instance stores all of the posts of its local accounts, and it downloads new posts of anyone followed by its local accounts, as notified by the ActivityPub protocol, but your instance doesn’t download old posts from other instances. This is why when you view someone else’s account profile in your instance, you might not see their older posts (unless someone else on your own instance was already following that account).

The data gaps are especially problematic on smaller Mastodon instances with fewer accounts, because on a smaller instance it’s less likely that another account on your instance was already following someone you’re interested in.

This is a great new feature, since the built-in Open original page menu command is not in a convenient location. It’s also useful for finding the RSS feed of a user.

Unfortunately, there is no way to assign keyboard shortcuts to extension buttons in Safari. So I wrote an AppleScript to click the button:

tell application "System Events"
    tell application process "Safari"
        set _items to entire contents of toolbar 1 of window 1
        repeat with _item in _items
            if _item's class is button and _item's description is "Homecoming for Mastodon" then
                click _item
                return
            end if
        end repeat
    end tell
end tell

and used FastScripts to assign the script a keyboard shortcut.

Unfortunately, the script has yet to work for me when run from FastScripts, even though I gave Accessibility access to both FastScripts and FastScripts Script Runner. It always fails with:

Error Number: -1719

System Events got an error: Can’t get toolbar 1 of window 1 of application process "Safari". Invalid index.

I assume this is some sort of TCC issue since the script sometimes works from Script Debugger but sometimes fails with a similar error.

Previously:

Update (2023-02-21): Jeff Johnson:

Homecoming for Mastodon version 2.1 is now available in the Mac App Store.

What’s New: Control-Command-M keyboard shortcut!

4 Comments RSS · Twitter · Mastodon

Michael, thanks for mentioning keyboard shortcuts! I've added the shortcut Control-Command-M, at your suggestion. Believe it or not, it's available now in version 2.1 for Mac, which cruised through app review in 45 minutes. (The iOS version with shortcut for iPad is forthcoming.)

@Jeff Thanks for the quick work. This is great!

After some more testing, and experimenting with adding a delay at the start, my script sometimes works from FastScripts. But it’s also failing more often from Script Debugger and Script Editor now, as do scripts (and Script Debugger’s explorer) that target other parts of Safari via accessibility. I continue to believe the cause is some sort of system issue.

Glad things worked out in the end,. Accessibility scripting often doesn't work when the application is not frontmost (such as when run from a script editor).

You may have more luck with your script if you add in:
activate application "Safari"
delay 0.1

@David Alas, that’s one of the workarounds I tried (even with a longer delay), but it didn’t help.

Leave a Comment