SKaplanOfficial/PyXA

Intermittent AttributeError when Invoking Shortcuts

Closed this issue · 5 comments

A few times in the past week, my code that invokes Shortcuts starts failing. Unclear what is triggering the issue, but once it occurs, the only way to resolve (that I've uncovered so far) is to reboot.

Example code

shortcuts_app = PyXA.Application("Shortcuts")
add_url = shortcuts_app.shortcuts().by_name("Add iTunes Store URL to Playlist")

results in

Exception has occurred: AttributeError
'SBApplication' object has no attribute 'shortcuts'

This seems to be because Shortcuts doesn't respond to Apple Events unless it is actively opened, but you should be able to use PyXA.Application("Shortcuts Events") to get around the problem. I might add a specific error message for this case, or at least adjust the documentation.

I was able to reproduce the problem and made a few more observations...

  • When the error occurs, I can still see Shortcuts as an active process in the Activity Monitor, even though the app appears closed. If I Force Quit from there, PyXA calls to Shortcuts start working again (no restart needed).

  • After a force quit, I can still run Shortcuts successfully without launching the app first. The API will open the app if it is not already open.

Based on this, I'm guessing this is more likely a Shortcuts bug. But I did want to share my observations as they are a different than what you mentioned above. Documentation changes may not be needed?

Do you see the problem at all when using Shortcuts Events instead? Just thinking that it might be worth mentioning in the documentation to avoid this and potentially other errors

Not so far, but the issue is intermittent. Can't hurt to acknowledge alternative either way.

Still unable to reproduce using System Events - maybe this is the best way.