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

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




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

Search: