@@ -645,36 +645,34 @@ async function transcribe() {
645645// ============================================================================
646646
647647/**
648- * Types text directly into the active text field without using clipboard .
649- * This inserts the text character by character using system automation .
648+ * Types text directly into the active text field.
649+ * uses Clipboard + Paste (Cmd+V) for better compatibility with accents/emojis .
650650 */
651651function typeText ( text ) {
652652 return new Promise ( ( resolve ) => {
653653 if ( process . platform === "darwin" ) {
654- // macOS: Use AppleScript to type text directly
655- // Escape special characters for AppleScript
656- const escapedText = text
657- . replace ( / \\ / g, "\\\\" ) // Escape backslashes first
658- . replace ( / " / g, '\\"' ) // Escape double quotes
659- . replace ( / \n / g, '" & return & "' ) ; // Handle newlines
654+ // macOS: Use Clipboard + Cmd+V to avoid character encoding issues
655+ const originalClipboard = clipboard . readText ( ) ;
656+ clipboard . writeText ( text ) ;
660657
661658 const script = `
662659 tell application "System Events"
663- keystroke "${ escapedText } "
660+ keystroke "v" using command down
664661 end tell
665662 ` ;
663+
666664 exec ( `osascript -e '${ script } '` , ( error ) => {
667665 if ( error ) {
668- console . error ( "Failed to type text:" , error . message ) ;
669- // Fallback: try clipboard method
670- clipboard . writeText ( text ) ;
671- exec (
672- `osascript -e 'tell application "System Events" to keystroke "v" using command down'` ,
673- resolve
674- ) ;
675- } else {
676- resolve ( ) ;
666+ console . error ( "Failed to paste text:" , error . message ) ;
677667 }
668+
669+ // Restore clipboard after a short delay to ensure paste completes
670+ setTimeout ( ( ) => {
671+ if ( originalClipboard ) {
672+ clipboard . writeText ( originalClipboard ) ;
673+ }
674+ resolve ( ) ;
675+ } , 200 ) ;
678676 } ) ;
679677 } else if ( process . platform === "win32" ) {
680678 // Windows: Use PowerShell to type text
0 commit comments