enzyme69 / blendersushi

Blender Sushi related scripts. Mostly about Sverchok, Geometry Nodes, Animation Nodes, and related Python scripts.
242 stars 33 forks source link

PYTHON Meta AI - Make Blender Talk to Siri Shorcuts #1353

Open enzyme69 opened 1 month ago

enzyme69 commented 1 month ago
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()
enzyme69 commented 1 month ago

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

enzyme69 commented 1 month ago
Screenshot 2024-05-09 at 08 44 24 Screenshot 2024-05-09 at 08 44 43
enzyme69 commented 1 month ago

BLEND kanji_game_010.blend.zip