1

I am using AirServer for Airplay on my Mac. As far as I know, AirServer does not provide an interface to run scripts on specific actions. However, I found a AirServer specific message inside the Console app whenever a device connects or disconnects to the service. I also tried the following in Terminal:

log stream | grep "AirServer"

I am looking for an efficient way to run a custom script whenever the process AirServer spills out a specific message (in my case connect/disconnect).

2
  • 2
    You might be able to take a similar approach to mine for Bluetooth described in my question here. You can use WatchPaths as I did if it writes to its own log file.
    – dissolved
    Apr 26 '20 at 12:50
  • Unfortunately, it does not write its own log file. Thanks anyway.
    – bbuecheler
    Apr 27 '20 at 14:02
1

AirServer implements a basic AppleScript interface which can tell you if AirServer is in use by calling:
osascript -e "tell application \"AirServer\" to inUse"

Another approach is create a basic app which monitors AirServer's notifications using NSDistributedNotificationCenter:
com.airserverapp.MirroringDidStart, com.airserverapp.MirroringDidStop, com.airserverapp.AudioDidStart, com.airserverapp.AudioDidStop, com.airserverapp.VideoDidStart, com.airserverapp.VideoDidStop

2
  • I tried the first suggestion and it worked in one direction. Meaning, after starting AirServer the script line returns "false". Once a device connects over Airplay, it turns "true". However, that's it, it never goes back. Also after disconnecting from AirServer, nothing happens and only a restart of the application helps. About the second suggestion, I could imagine, that this works, but I am not familiar with Swift programming. Therefore this will take a bit longer, at least for me.
    – bbuecheler
    Apr 27 '20 at 14:00
  • I did some further testing. The AppleScript command tell application "AirServer" to inUse does only work if you actually run some music. If you only connect and disconnect, the state inUse stays True. That is still a bit error prone and I will have to look for a fix/workaround.
    – bbuecheler
    Apr 27 '20 at 15:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .