by phillco · 3y ago · 0 comments
(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.
Been using this for about a decade now.
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 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.
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 tellIf 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.
https://www.amazon.com/Conquering-Carpal-Syndrome-Repetitive...
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.
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.
Sounds about right. Nice to know there's a name for it!
I've used them daily for 5+ years.
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...
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...
/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!')"Are there any good examples of doing this?
There are lots of examples just by googling. The script editor has a dictionary for every application you can natively script.
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 :)
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.
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
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.
I recommend breaks and rest over strengthening exercises when dealing with hand pain. Learn preventative measures
Now they just need to bring back QuickDraw GX, OpenDoc and PowerTalk (please don’t for all that is holy)