I am looking for a way to run a HomeKit scene from a Pythonista script.
I know I could do it, using the Apple's Shortcuts app. But this approach is problematic, when I want to execute two scenes from a script. The problem seems to be passing the execution flow from the Shortcuts app back to my Pythonista script and continue it's execution. When I call my Pythonista script from the Shortcuts app, then the Shortcuts app waits for my script to finish. During the waiting I can not call another shortcut.
So I was wondering if there might be a way to run HomeKit scenes without the indirection of using the Shortcuts app.
I found this post: https://forum.omz-software.com/topic/4696/homekit/4, but it's two years old.
Thank you very much
I am trying to get the currently played item from Apples Music App. My code looks like this:
from objc_util import * def main(): NSBundle.bundleWithPath_( '/System/Library/Frameworks/MediaPlayer.framework').load() MPMusicPlayerController = ObjCClass('MPMusicPlayerController') MPMediaItem = ObjCClass('MPMediaItem') player = MPMusicPlayerController.systemMusicPlayer() item = player.nowPlayingItem print(item) print(item.title) main()
My problem is, that I do not know how to get values from "nowPlayingItem". I get this exception:
print(item.title) AttributeError: 'ObjCInstanceMethodProxy' object has no attribute 'title'
I am thankful for any hints.
Thank you for your ideas and I am sorry for my late reply.
I tried the previous suggestion and I think the query is not working properly. If I iterate the query result it returns all my media items. But I also do not see the problem. As far as I understood the Apple documentation, it looks correct to my.
I tried a different approach:
from objc_util import * def main(): NSBundle.bundleWithPath_( '/System/Library/Frameworks/MediaPlayer.framework').load() matchingItem = ["928428096"] # StoreId of "Songs of innocence" MPMusicPlayerController = ObjCClass('MPMusicPlayerController') player = MPMusicPlayerController.systemMusicPlayer() player.setQueueWithStoreIDs(matchingItem) player.play() main()
I got the StoreId from this web site:
This is working, but not as comfortable as I was looking for.