enzyme69/blendersushi

PYTHON Meta AI - Make Blender Talk to Siri Shorcuts

enzyme69 opened this issue · 3 comments

import bpy
import pyperclip
import chardet
import subprocess

class SendToSiriShortcutsOperator(bpy.types.Operator):
    """Send text to Siri Shortcuts"""
    bl_idname = "view3d.send_to_siri_shortcuts"
    bl_label = "Send to Siri Shortcuts"

    def execute(self, context):
        # Get the active text object
        text_obj = context.object

        # Check if the object is a text object
        if text_obj.type == 'FONT':
            # Get the text data
            text_data = text_obj.data
            
            # Detect the encoding of the text
            encoding = chardet.detect(text_data.body.encode())['encoding']
            
            # Copy the text to the clipboard (encode to utf-8 and decode to string)
            clipboard_content = text_data.body.encode('utf-8').decode('utf-8')
            pyperclip.copy(clipboard_content)
            
            # Send the clipboard content to Siri Shortcuts
            subprocess.run(['shortcuts', 'run', 'Clipboard Kanji'])
            
            # Print the text (encode to utf-8 and decode to string)
            print(clipboard_content)
        else:
            print("Please select a text object")
        return {'FINISHED'}

def register():
    bpy.utils.register_class(SendToSiriShortcutsOperator)

def unregister():
    bpy.utils.unregister_class(SendToSiriShortcutsOperator)

if __name__ == "__main__":
    register()

In case the CLIPBOARD is displaying weird characters, run Blender from the Terminal in macOS.