AndrewK
AndrewK

Reputation: 13

Place cursor in messages app text box

I am looking for a script that will place the cursor in the text field in the Messages App. I have looked for a keyboard shortcut to do this but cannot find one. Can anyone provide a script, or a similar one I can modify.

NB I am not a programmer or very familiar with AppleScript, but have been able to modify scripts that are close to my needs.

I need this as I am trying to make the messages app controllable using the built in dictation feature in Mac OS. I need a script I can assign to a voice command to place the cursor in the text field so that I can then dictate a message.

Many thanks.

Upvotes: 1

Views: 439

Answers (2)

wch1zpink
wch1zpink

Reputation: 3142

If you are using dictation commands, in any application all you need to do is say the command “Show Numbers” and you will see this:

enter image description here

Then you would just say the command “Twenty” which will place your cursor right where you want it… in this case it would be the text field


Also speaking the command “Show Comands” Will open up this window listing tons of dictation commands.

enter image description here

Upvotes: 1

user3439894
user3439894

Reputation: 7565

The following was tested and works under OS X 10.8.5 and Messages 7.0.1 and may need to be adjusted for other versions of OS X/macOS/Messages:

tell application "Messages"
    activate
    tell application "System Events"
        set focused of text area 1 of scroll area 4 of splitter group 1 of window 1 of application process "Messages" to true
    end tell
end tell

Note: This is coded with the assumption that Messages is already open with an open window. Additional coding will be necessary, in the form of try and or delay and or on error statements as needed and appropriate otherwise.


Here's an example of how I'd code it otherwise, which handles whether or not Messages is open, has its window showing, etc.

on setFocusToTextArea()
    tell application "System Events"
        if (count of windows of application process "Messages") is equal to 0 then
            click UI element "Messages" of list 1 of application process "Dock"
            delay 0.25
        end if
        try
            set focused of text area 1 of scroll area 4 of splitter group 1 of window 1 of application process "Messages" to true
        end try
    end tell
end setFocusToTextArea

tell application "Messages"
    if running then
        my setFocusToTextArea()
    else
        activate
        delay 2
        my setFocusToTextArea()
    end if
    activate
end tell

Note: If Messages is closed when this script is run, the delay 2 command gives time for Messages to open before the other code runs. The value of the delay command can be adjusted as appropriate for the speed of your system.

Upvotes: 0

Related Questions