Cannot print period ('.') from simple AppleScript to VMware Fusion virtual machine So I have a simple AppleScript that I think should type a bunch of keys, but the period character doesn't print in VMware Fusion's virtual machines. This is odd because my period key (.) enters a period like normal in those VMs.

MCVE

Here is my latest version that I tried:

on run {input, parameters}

    set file_text to "this another test: ... hello ..."
    delay 0.3
    repeat with ch in file_text
        tell application "System Events" to keystroke ch
        delay 0.1
    end repeat

    return input
end run


I built this as a service in Automator. I run this by going to my application, then in the Title bar I select Services -> quicktype.

Expected Behavior

It should just type the text this another test: ... hello .... In many application, it does exactly that.

True Behavior

In a FreeBSD VM, pressing . renders a period at the shell (like normal). When the above script runs, however, the periods look like backspaces. End result:


In a Windows VM, . renders a period in Notepad (like normal). When the above script runs, however, the periods seem to be ignored completely. End result:


Questions

Is there a way to truly emulate pressing the keys from a string of characters in AppleScript? Because clearly the above way isn't doing that.

Does anyone know why the behavior I described above is happening? Why does this work in TextMate and Terminal, and other mac apps, but not in Fusion VMs?
I don't understand why this isn't working, however I do have a fix. I figured out that doing tell application "System Events" to key code 47 sends a period correctly.

So, I wrapped my read into a conditional like this:

on run {input, parameters}

    #set input_file to "/path/to/file"
    #set file_text to read input_file
    set file_text to "test: ... hello ..."
    delay 0.3
    repeat with ch in file_text
        if ch as string = "." then
            tell application "System Events" to key code 47
        else
            tell application "System Events" to keystroke ch
        end if
        delay 0.1
    end repeat

    return input
end run