0

My automator service is as follows:

Workflow receives no input in Google Chrome.app Input is entire selection (checkbox not checked)

Run Applescript

    on run {input, parameters}
     tell application "Google Chrome" to activate
     tell application "System Events"
      keystroke "i" using {control down, option down}
      keystroke "r"
     end tell
     return input
    end run

In Security & Privacy -> Privacy -> Accessibility, both Automator and Google Chrome are listed and checked, and under Automation, Google Chrome has System Events.app checked.

With Google Chrome open (specifically on a Google Sheets tab), this works:

  • When I run the step from Automator
  • When I run the entire service from Automator
  • When I run the service from the Chrome menu

However, it does not work when I use the keyboard shortcut I assigned in System Preferences: command+option+control+n. A cogwheel briefly appears in the menu bar then goes away, and I even added a notification center action to tell me the service ran (it does) - but nothing happens in Google Sheets. I have tried other keyboard shortcuts to no avail.

Any help appreciated. Honestly if Google would just add a two-stroke "insert row" hotkey, that would relieve me of this whole idiotic exercise :)

  • Did you try using another shortcut? maybe there is a conflict? Also, you could try using 'Any App' instead of Chrome, since you are already activating it via code. – Mateus Ribeiro Apr 17 at 16:07
  • I tried several very obscure shortcuts, and several more today. I also tried with 'Any App'. No change in behavior. – jtacq Apr 21 at 17:22
1

It is working fine here.

However in my experience most problems using UI sequences are related to the lack of delay for the system to execute the thread. Often it will process the strokes so fast that the actions are not yet finished before automator sends another command, causing overlays and hence ignoring the last action. A simple solution is providing tiny delays between each stroke.

Also the return input line can be causing issues, because the input is empty and there is no parameters.

I have tested this script successfully:

on run
    tell application "Google Chrome" to activate
    delay 0.1
    tell application "System Events"
        key code 34 using {control down, option down}
        delay 0.1
        key code 15
    end tell
end run
| improve this answer | |
  • 1
    I tried removing the return input, and adding in the delays. I also tried the delays at 0.5 just to be thorough. Unfortunately, this had zero impact on my originally reported behavior, aside from the fact that it was a little slower when successfully running it from Automator or the services menu. I also copied and pasted your code block directly into Automator and it still didn't work. This works in every circumstance EXCEPT the keyboard shortcut, but the shortcut DOES result in a cogwheel in the menu, indicating the script is running, plus I get a notification I added as a second step >.> – jtacq Apr 23 at 21:11
  • Ok, actually, after giving this some "time" (I hate problems like this)... it seems to be working now, having copied your code directly into mine. – jtacq Apr 23 at 21:16
  • Actually, it only works sometimes... and it doesn't appear to be related to frequency. So, I'm now at a complete loss. Now, sometimes it's adding an 'r' character to the cell I have selected. – jtacq Apr 23 at 21:20
  • @jtacq You could try editing the shortcuts at Google Sheets (Command+/) and using another combination. The default keys for this action is command+option+shift+= but apparently you will still need two steps. – Mateus Ribeiro Apr 25 at 3:15
  • Yeah, when you think about those 2 (awkward) steps in the context of adding 5-10 rows it rapidly becomes a finger traffic jam. Since the key to add a row about is "r", you could remap it to command+option+shift+r, but then you are still stuck with the very awkward action of pressing and releasing command+option+shift alternately. This isn't very repeatable without error. – jtacq Apr 27 at 13:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .