Jump to content

New to Alfred and trying to build my first Workflow


Recommended Posts

Hello Alfred Forum!

 

I am brand new to using Alfred and absolutely love it right now! 

 

I'm not sure if this is actually possible, but I'm trying to build a workflow that will pause Apple Music when a Zoom call is launched. I'm not good at coding and think I've made several mistakes. I'm able to get the script to run, but it doesn't pause when a Zoom call is launched, but it does resume after I finish the call. The other issue I'm having is that I can't pause Apple Music outside of a Zoom call. Any help would be appreciated! 

 

EDIT: I'm using Alfred 5.5 on the beta for Sequoia OS. I was running it via the hotkey.  

 

Here is a copy of the code I'm using:

import time
import AppKit
import os

def is_zoom_active():
    zoom_running = False
    for app in AppKit.NSWorkspace.sharedWorkspace().runningApplications():
        if app.localizedName() == 'zoom.us':
            zoom_running = True
            break
    return zoom_running

def is_on_a_call():
    # Check if Zoom has any active windows
    zoom_windows = AppKit.NSApplication.sharedApplication().windows()
    return len(zoom_windows) > 0

def pause_music():
    os.system("osascript -e 'tell application \"Music\" to pause'")

def play_music():
    os.system("osascript -e 'tell application \"Music\" to play'")

def main():
    was_on_call = False

    while True:
        zoom_active = is_zoom_active()

        if zoom_active:
            on_call = is_on_a_call()
            if on_call and not was_on_call:
                print("Pausing music...")
                pause_music()
                was_on_call = True
            elif not on_call and was_on_call:
                print("Resuming music...")
                play_music()
                was_on_call = False
        else:
            # Ensure music is playing if not on a Zoom call
            if was_on_call:
                print("On Zoom call but app not recognized. Pausing music if playing.")
                pause_music()
                was_on_call = False

        time.sleep(5)  # Check every 5 seconds

if __name__ == "__main__":
    main()

 

Thank you for your time! 

Alurus

image.thumb.png.afea996c2a071e68f7211d40d0f45a65.png

Code Part 1.png

Code Part 2.png

Edited by Alurus
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...