Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you're on macOS, you can do a small piece of this natively with AppleScript (or anything that can send apple events) in Chrome or Safari -- namely, you can iterate through windows or tabs, view their source code, and execute arbitrary javascript you pass (there's a one time security option you have to accept). This can be handy for quick automations if you don't want to install anything.

(Background: I have RSI, so I've been developing some integrations between applications and Talon Voice (https://talonvoice.com/). AppleScript ends up being surprisingly valuable/fast/reliable for applications that support it. I also built an integration with iTerm2's Python API before noticing that everything I was trying to do was already supported by its AppleScript dictionary, and was faster. In Google Chrome, the "iterate through tabs and execute javascript in them" is very useful for automating Google Meet muting/unmuting.)

Nothing against this excellent project though; I'm a big fan of Omar's Twitter! And I suspect most here will appreciate the easier scriptability of the filesystem approach than dealing with the atrocious syntax of AppleScript.



You don’t need to write AppleScript yourself, someone else has already done the hard work with Scripting Bridge and you can simply enjoy an easy-to-use CLI: https://github.com/prasmussen/chrome-cli

Been using this for about a decade now.


interesting, what are your use cases?


Safari, not Chrome, but here's an AppleScript I use to map a trackpad gesture to the "next page" link on a wide variety of Web sites,

    tell application "Safari" to do JavaScript "
        (() => {
            const loc = Array
                  .from(document.querySelectorAll('[rel=\"next\"], .next, [title=\"Next page\"]'))
                  .map(i => i.getAttribute('href')).filter(i => i)[0];
            if (loc) {
                document.location = loc;
            }
        })()
    " in document 1
s/next/prev/g s/Next/Previous/ for the matching "previous page" script.

Note that this requires Safari's "AllowJavaScriptFromAppleEvents" preference to be set, either via a "Develop" menu option or directly in its preferences file via, e.g., the

    defaults write com.apple.Safari AllowJavaScriptFromAppleEvents -bool TRUE
shell command, and that this setting allows any program you authorize[1] to send Apple Events to Safari to potentially do Terrible Things. Given that the setting is both disabled and hidden by default, and additionally gated by an opt-in privacy preference, it's presumably an unlikely target for garden-variety malware, however.

[1] Check the Automation group in the Privacy tab of the Security & Privacy preference pane for a list of programs so authorized.


I can’t answer that question exactly because that’s driving Chrome, but I wrote an AppleScript the other day to make zoom less dreadful.

I annotate on screens all day and there are no useful shortcuts for moving between drawing and erasing. Also the drawing button requires 2 clicks. I’ve wired my wacom tablet so the two buttons fire off shortcuts, they run a service I’ve registered in the menus, they run the applescript, it fishes about for the right windows in zoom and clicks the buttons. It could not have worked but it just happens to because I can trigger a button and then focus moves to the next button (which I can’t otherwise target) and then I can push “space” to get the job done.


Here’s one of the scripts if anyone wants to see how weird it all is.

    tell application "System Events"
    repeat with theProcess in processes
        if not background only of theProcess then
            tell theProcess
                set processName to name
                set theWindows to windows
            end tell
            set windowsCount to count of theWindows

            if processName is "zoom.us" then
                repeat with theWindow in theWindows
      tell theWindow
   set theSize to size
                        set windowName to name
      end tell
                    if windowName is "annotation panel" then
                        if item 1 of theSize is 776 then
                            tell theWindow to tell button 5 to click
                            key code 49
                        else
                            tell theWindow to tell button 4 to click
                            key code 49
                        end if
      end if
                end repeat
            end if
        end if
    end repeat
    end tell


If I were you I would find out which “RSI” you have. Mine wasn’t from “overuse” per sé, just posture and needing to stretch/exercise.

If your RSI is Carpal Tunnel or Cubital Tunnel Syndrome, a quick and easy surgery is the answer.

If your RSI is tendinitis (unlikely, for all the times I see people self-diagnose with it) rest is your best bet.

If your RSI is arthritis, there are medications and even surgeries out there to help with it, but that’s the easiest one to diagnose because it just requires looking at an x ray of your hand.

You may have carpal tunnel syndrome-like symptoms, but that likely just means you have nerve impingement somewhere between your cervical (neck area) spine and your hand.

I’m not a doctor, but through personal experience I can tell you, you probably have the power to get rid of your “RSI” without resorting to dictation software and so on.


Regarding stretching, I found the book Conquering Carpal Tunnel Syndrome to be a huge help. It has lots of suggestions for kinds of stretches to do based on the kind of work you do, but my big takeaway (and according to the author, the most important part) was how to do the stretches: only stretch until you barely feel a stretch, then hold there until you feel a sense of release. In my experience that was more effective than the “stretch until you feel a good strong stretch” strategy.

https://www.amazon.com/Conquering-Carpal-Syndrome-Repetitive...


I have a copy of this which I no longer need. If anyone in Australia wants it hit me up and I'll mail it to you. @johnnydecimal@hachyderm.io.

FWIW -- I know this isn't an RSI thread -- mine was 100% fixed by changing my desk. It was too high, and my classic 5-wheeled office chair was unstable. I lowered the desk to about 68cm (I'm 172cm) and bought a chair with wooden legs (Ikea, ~$80), started doing light stretches in the morning, and that fixed it for me.

I made the desk from Ikea cabinets and a $100 plain wooden door. So it's a) cheap, b) massive, and c) I can screw things in to the underside.


I significantly reduced the symptoms of my carpel tunnel by changing from a normal height mechanical keyboard to one with slim key caps. I really miss my Das Ultimate but the difference is really noticeable.


Aah yep, I also had a Das, and the Filco Majestouch 2. Beautiful keyboards. Sold 'em.

Now I use the very-average Microsoft Sculpt Ergonomic. Low keycaps, low travel. And of course a split layout.

Do not use the execrable MS mouse that comes with that keyboard. I love the MX Anywhere series, I currently use a 2 and a 3. They're light, so you can nudge them round with your fingers without having to move your arm too aggressively.


Ah yes I know that keyboard - mine is a Keychron K2 V2 with optical switches. It's decent to type on but I miss having a volume knob and proper function keys.

I find it really helps not having the number pad - it means my mouse can be closer to the keyboard so my wrists are straighter.

For a mouse I use a MX Master 3 which I'm very happy with.


I tried an MX Master 3 and 2S, I also have the MX Ergo trackball mouse and the Logitech vertical mouse. The vertical mouse is what I ended up with, but for years I would switch mice, switch between several mice within a day, switch hands - and they were all half-measures that just kind of delayed the "degeneration". The issue, it would seem, was not the mouse or overusing the mouse. The issue seems to have come from my shoulder area (Thoracic Outlet Syndrome aka TOS / Pec. Minor Syndrome), which a vertical mouse will uniquely address as it allows your shoulder to be less interiorly-rotated than a standard mouse, even a trackball mouse that is not vertical.

I remember reading a Medium article a while ago about a software engineer who described how he addressed his "RSI", which I suspect was just TOS - he switched to an ergonomic keyboard and vertical mouse, which over a period of MANY MONTHS more or less resolved his RSI. He talked about how he still has to be careful and take breaks often. I really think, especially considering his age (20s), he could have kept the mouse and keyboard he had, if he just engaged in posture-correcting shoulder stretches and strength exercises.


I tried the Master but found it a tad large. As above, I'm not a ginormous person: 172cm (5' 8", just), 70kgs. I don't have huge hands. I found pushing round the Master to be a bit too much work, which sounds preposterous but ¯\_(ツ)_/¯.

The Anywhere is just smaller, lighter. More nimble.


Interesting! I like my mouse to be as heavy has possible, I find it more preside and exacting.


I also use an MX Master (2S), and wish I would have switched sooner. It can connect to 3 devices (via Bluetooth or USB receivers) with a button on the bottom to switch, and an “infinite” scroll wheel with multiple modes, which is awesome!


Any experience with low-profile mechanical keyboards, seems like a potential compromise between something like the Das, and the microsoft sculpt?


No, I wasn't aware of any.


My personal trainer told me the same- you won't gain flexibility by "forcing" the stretch, only by stretching just beyond where the muscle wants to stop, holding it there for around 30 seconds (and you should feel a "release"), and repeating the next day.


+1

This is solid advice! I had "RSI" for years (could barely type or write) and in the end what solved everything were exercises to improve my posture and strengthen my back, neck and shoulders.


There's a lack of awareness too - I saw three orthopedic surgeons and one neurologist and none asked me about, mentioned, or tested me for Thoracic Outlet Syndrome (which is likely what you had based on what fixed your symptoms). I only learned about TOS myself after they ruled out Carpal Tunnel Syndrome and going back to Google to try to find what could be causing CTS symptoms other than CTS.


> Thoracic Outlet Syndrome (which is likely what you had based on what fixed your symptoms)

Sounds about right. Nice to know there's a name for it!


Shameless plug: I've made a set of AppleScripts I call "Tab Transporter" for moving groups of tabs between browsers. The code is painful to write when you're used to a normal programming language, so these examples could be useful for anyone else looking to interact with browser tabs via AppleScript.

I've used them daily for 5+ years.

https://github.com/tedmiston/tab-transporter


Funny, I do similar [1] though my solution is very basic compared to yours. The script allows me to quickly move the current tab from Firefox or Safari to Arc Browser [2] (which uses Chrome under the hood).

I use the following key-bindings ⌥⌘F or ⌥⌘S in Raycast [3] to activate a tab move to Arc from Firefox or Safari, respectively.

1: https://github.com/ayewo/raycast-script-commands/tree/main/b...

2: https://arc.net

3: https://www.raycast.com/


Nice, thank you!


I used to scan all the tabs in open browser windows to list all URLs.

See also https://chromedevtools.github.io/devtools-protocol/ with Playwright et al., even Excel VBA: https://github.com/PerditionC/VBAChromeDevProtocol

Many sites fight against automation, see https://github.com/ultrafunkamsterdam/undetected-chromedrive...


Just to show folks how simple this is, here's the JavaScript (JXA) version of the AppleScript code needed to run JS in the current active tab:

   /usr/bin/osascript -l JavaScript <<EndOfScript
      var current_tab = Application('Google Chrome').windows[0].activeTab();
      current_tab.execute({  javascript: 'alert(1)'  })
   EndOfScript
Once you figure it out it's not too tricky. For example, I have shell utils for converting all links on a page to "in current tab links" by removing the `target` attr on <a> tags:

    function chromeJS() {
       INPUT="$1";
       INPUT=${INPUT//\"/\\\"} ## escape quotes
       INPUT=${INPUT//\'/\\\'}
       /usr/bin/osascript -l JavaScript <<EndOfScript
          var current_tab = Application('Google Chrome').windows[0].activeTab();
          current_tab.execute({  javascript: '$INPUT'  })
    EndOfScript
    }
    ...
    $ chromeJS "document.querySelectorAll('a').forEach(a => a.removeAttribute('target')); alert('Made all links in-tab links!')"


"If you're on macOS, you can do a small piece of this natively with AppleScript (or anything that can send apple events) in Chrome or Safari -- namely, you can iterate through windows or tabs, view their source code, and execute arbitrary javascript you pass (there's a one time security option you have to accept). This can be handy for quick automations if you don't want to install anything."

Are there any good examples of doing this?


sure, for example this pauses every youtube video in every chrome tab: tell application "Google Chrome" repeat with theWindow in every window repeat with theTab in (every tab of theWindow) if (URL of theTab) contains "youtube.com" then execute theTab javascript "document.querySelectorAll('video, audio').forEach(e => e.pause())" end if end repeat end repeat end tell

There are lots of examples just by googling. The script editor has a dictionary for every application you can natively script.



Interestingly, all the AppleScript functionality is built on an objective-c api called ScriptingBridge and it’s relatively easy to use a real programming language for the same sorts of things. JavaScript is natively supported by Script Editor, but there’s bindings for Ruby and Python too. I’ve wrapped it up in Common Lisp for my own use: https://github.com/fiddlerwoaroof/objc-lisp-bridge/blob/mast...


Love to hear more about this. I also suffer from RSI and would love to know if it’s helped changing input to voice


Have you got any suggestions for coping with RSI? I'm having significant issues.


If you're programming, definitely check out Cursorless: https://www.cursorless.org/.

Talon itself provides noise and speech recognition, and provides the framework that allows you to build automations with any program; Cursorless really helps make programming by voice feel comparable to typing.

For me, it's a combination of introducing alternate input methods (largely voice, but noises are also very additive -- they very well for fast/discreet actions, whereas voice is higher bandwidth but lower latency), as well as building higher-level and better integrations with applications. But I still have always to go personally.

I've been meaning to write up a blog post with everything that I've learned, but you know how it is :)


Edit: I meant to say that voice is higher bandwidth _and_ higher latency, not lower.


+1 on that blog post!


Have you tried a book on the mind body connection of pain? It helps some people with RSI: https://www.amazon.com/Healing-Back-Pain-Mind-Body-Connectio...


That’s also how I got rid of my RSI.

Once I ended that one bad relationship in my life, my mind stopped messing up the most used part of my body to send me signals that I’m actually chewing on life’s gristle.

My wrists have been pain free for 15 years. Without surgery. Without therapy. Without a change in work hours.


It's all about hardware. I've addressed it quite well with a three-pronged approach:

1. Motorized standing desk - typing from varying postures keeps strain spread out

2. Kensington trackball mouse - less hand sweeping / temptation to drags wrist on table

3. Ortholinear "Planck" keyboard - modifier keys accessible via thumb and programmable layers more generally can completely eliminate painful hand poses and keep fingers on the home-row


Change is good. I find using a variety of mice helps. Rollermouse, trackpads, rockmouse, carpal tunnel mouse(quadraclicks), mousetrapper.

For the dragging wrist problem, I really like the reloot or other similar gliding palm rests. I find upgrading them with ceramic lights makes a big difference.


Personally I find the Kensington trackball mouse made my carpel tunnel a LOT worse, they're not for everyone.


With my particular RSI I also can't use a standard trackball, but I swear by my thumb trackballs. (But every body is different, every injury is different, etc.)


The Kinesis Advantage 2 keyboard fixed mine. I also use a Logitech trackball instead of a mouse.


Devote a 4 digit budget for a new workspace that relieves RSI causing movements.


You don't need to spend that much. I mean, go for it, it sounds fun, but just getting a desk the right height (i.e. probably lower than it is now) and a stable chair solved mine. See sibling comment here.

https://news.ycombinator.com/item?id=34852007


Split vertical keyboards with very very light switches. I use Sofle Choc and have the sides at shoulders width apart

I recommend breaks and rest over strengthening exercises when dealing with hand pain. Learn preventative measures


If you had told me in 1992 when AppleScript was first introduced that it would be around for over 30 years across three processor transitions, I would not have believed you.

Now they just need to bring back QuickDraw GX, OpenDoc and PowerTalk (please don’t for all that is holy)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: