2

I'm new to Automator and AppleScript, so, apologies in advance if this question is answered/stupid/obvious/impossible.

My organisation runs the Zoom app, I can't install Zoom plugins etc, but I want to be able to, externally from Zoom, monitor if I'm on a Zoom call or not, and run a shell command or similar (say, to toggle an "ON AIR" USB light).

I assume I can write an AppleScript that runs at startup, hidden from Dock etc, that loops listening for an application, then a window of that application, then perform the action, and continues looping checking for the existence of the window, once it is no longer found, performs another action. Is that the right way to approach this?

Also, note here that just having the Zoom application open doesn't mean we're on a call - when the call ends, most of the time people keep Zoom open. It's only the Zoom call window that gets closed. Luckily, whenever there is a Zoom call, it always seems to be in a window called "Zoom Meeting" and that doesn't change.

I'd prefer not to use any third-party software unless it's free and open source.

What's the best way to achieve this?

Chris
  • 120
  • Would a script to trigger the action, required, run Zoom, wait for Zoom to quit and run another action also work in your scenario? How do you typically join a zoom call, by starting the application or by clicking a link? – nohillside Oct 22 '22 at 13:31
  • @nohillside Could be either, from Outlook, from Slack, from just opening Zoom itself. I think I'd rather have something monitoring for the existence of a window "Zoom Meeting" than rely on opening Zoom in any special/different way. – Chris Oct 22 '22 at 22:01
  • 2
    Get Keyboard Maestro then. Yes, it is neither free nor open source but it gets the job done easily. – nohillside Oct 22 '22 at 22:34
  • @Chris So what happened with this question? Did you accept an answer? – mhopeng Nov 03 '22 at 05:45

2 Answers2

2

You can do with this with AppleScript. However, because the Zoom application does not support AppleScript, you have to use the Finder Accessibility features, and that means you have to allow your AppleScript application to control your computer. It is a one-time step, and a minor security risk imho.

Create the following script using the Script Editor:

tell application "zoom.us" to activate

tell application "System Events"

tell process "zoom.us"

    repeat until window "Zoom Meeting" exists
        delay 1
    end repeat
    -- do something here (On Air light)
    -- for example, run a shell script:
    -- do shell script "command"
    display dialog "Zoom Meeting Started" buttons "OK" default button "OK"

    repeat until not (window "Zoom Meeting" exists)
        delay 1
    end repeat
    -- do something here
    -- for example, run a shell script:
    -- do shell script "command"
    display dialog "Zoom Meeting Ended" buttons "OK" default button "OK"

end tell

end tell

Save this script as an application, and then try to run it. You will get the Finder security warning about needing to give this application access to Accessibility features. After you enable this under "Security & Privacy" in the System Preferences, it will work fine.

Once the application is working on your system, you can add it to the list of Login Items like any other application to make it run automatically on startup.

mhopeng
  • 188
  • 6
  • @Chris This might help in getting the script to run on startup: https://apple.stackexchange.com/questions/336960/how-do-i-get-an-applescript-application-to-automatically-run-at-login – Louie Louie Oct 30 '22 at 20:24
  • Good point; I added that to the answer. – mhopeng Oct 31 '22 at 18:05
1

Keyboard Maestro is definitely your best solution to this and so many other scripts and shortcuts in the future! I don't know the particulars of your USB light, but the following simple action should prompt an alert when Zoom launches. You could write a similar script to reverse the process when Zoom quits.

enter image description here

  • Unfortunately Keyboard Maestro is not free and open source, it's commercial and closed source. – Chris Oct 30 '22 at 18:53