Repository navigation
Closed
Labels
feature-requestRequest for new features or functionalityhelp wantedIssues identified as good community contribution opportunitiesterminalGeneral terminal issues that don't fall under another label
Milestone
Description
The Issue
I'm writing an AppleScript for opening a terminal and writing some stuff in it, the problem is that without an hard coded delay between the action "open the terminal" and the action "write this stuff in it" it doesn't work.
This is what, ideally, should be working (minus the useless delay call):
tell application "Visual Studio Code" to activate
tell application "System Events"
keystroke "`" using control down
delay 0
keystroke "placeholder"
end tellThis is what I see in the terminal if I run the AppleScript with different delay values:
- 0:
fabiomac:project fabio$❌ - 0.1:
fabiomac:project fabio$❌ - 0.15
placeholderfabiomac:project fabio$ placeholder❌ 😮 - 0.2
fabiomac:project fabio$ placeholder✅
IMHO this is broken because I shouldn't have to hard code environment-dependant delay calls in my AppleScripts, and consequentially I shouldn't have to wait those extra seconds.
My Setup
- VSCode Version: Code 1.13.1 [Unsupported] (379d2ef, 2017-06-14T18:13:05.928Z)
- OS Version: Darwin x64 16.7.0
- Extensions:
| Extension | Author | Version |
|---|---|---|
| EditorConfig | EditorConfig | 0.9.3 |
| status-bar-tasks | GuardRex | 0.2.0 |
| beautify | HookyQR | 1.1.1 |
| crane | HvyIndustries | 0.3.6 |
| vscode-docker | PeterJausovec | 0.0.16 |
| code-settings-sync | Shan | 2.8.1 |
| sort-lines | Tyriar | 1.3.0 |
| vscode-color | anseki | 0.4.1 |
| vscode-custom-css | be5invis | 2.3.2 |
| gitignore | codezombiech | 0.5.0 |
| vscode-svgviewer | cssho | 1.4.2 |
| vscode-dash | deerawan | 1.5.0 |
| python | donjayamanne | 0.6.5 |
| applescript | idleberg | 0.6.0 |
| indentation-level-movement | kaiwood | 1.1.1 |
| graphql-for-vscode | kumar-harsh | 1.4.1 |
| ecdc | mitchdenny | 0.10.3 |
| vscode-duplicate | mrmlnc | 1.1.0 |
| debugger-for-chrome | msjsdiag | 3.1.4 |
| ava | samverschueren | 0.4.0 |
| todotasks | sandy081 | 0.5.0 |
| php-ci | small | 0.2.0 |
| Align | steve8708 | 0.2.0 |
| cordova-tools | vsmobile | 1.2.7 |
| vscode-react-native | vsmobile | 0.3.2 |
| change-case | wmaurer | 1.0.0 |
Metadata
Metadata
Assignees
Labels
feature-requestRequest for new features or functionalityhelp wantedIssues identified as good community contribution opportunitiesterminalGeneral terminal issues that don't fall under another label
Activity
Tyriar commentedon Jun 21, 2017
Fabio Spampinato (@fabiospampinato) the problem is that the terminal takes more than 0ms to start up? It takes time to spin up the pty and attach everything, a little longer than other terminals because everything is going through V8 first.
fabiospampinato commentedon Jun 21, 2017
Daniel Imms (@Tyriar) the problem is that I have to put workarounds in my AppleScripts in order for them to work.
Of course it won't be as fast as a native terminal, but perhaps instead of just throwing away whatever is typed during the time where the terminal panel is in focus but the new pty hasn't started yet we could store it and replay it back once the pty started. What do you think?
Tyriar commentedon Jun 21, 2017
Sure, I'll add it to the backlog and open it up for PRs. To anyone interested in implementing this you will need to listen to key strokes in TerminalInstance and add them to a queue. Once the pty is ready then push the events through the normal mechanism.
fabiospampinato commentedon Jun 21, 2017
Sounds nice, thanks!
cleidigh commentedon Jun 21, 2017
Fabio Spampinato (@fabiospampinato)
Daniel Imms (@Tyriar)
FTW - somewhere in the last month/1.5months I started to see a similar problem
under Windows using the run commands function on a text file I use for various DOS commands
building VS code running git commands, et cetera. before I could use run commands
in the terminal would open and run the command for 100% without fail
recently the terminal opens but the subsequent command is only executed seventy five percent
of the time and I have to redo the run commands
you can mark me down to do a PR on this
cleidigh commentedon Jun 21, 2017
Daniel Imms (@Tyriar)
Fabio Spampinato (@fabiospampinato)
I haven't looked at the code yet, but I'm assuming there could be some state awareness issues.
for instance , in order to track and queue the keystrokes the state in context of VS code has to transition
to the terminal context (presumably minimal time, but not zero as you stated above).
This means there will always be a window where keystrokes from an automation program
such as AppleScript will be missed. doing the queuing between the time the open terminal
command is executed and the PTY is ready only reduces the window but not to zero.
I also realized my situation with the VSC run commands is related but different since the run command is an internal command.
I'll look into what I think this takes
14 remaining items
Merge pull request #30106 from cleidigh/terminal-q/imp
fabiospampinato commentedon Jul 5, 2017
Sounds great, thanks a lot for your time!
Tyriar commentedon Jul 5, 2017
Fabio Spampinato (@fabiospampinato) thanks for the suggestion, this will make things feel much snappier 🙂
cleidigh commentedon Jul 5, 2017
Fabio Spampinato (@fabiospampinato)
Daniel Imms (@Tyriar)
FYI I have limited means of doing work on OS X since I don't have Dragon voice Control for OS X
the only way I can do OS X work is a remote VNC connection which introduces its own set of problems
I finally got a chance to look at OS X unfortunately it does have different timing
using the exact same script as Fabio Spampinato (@fabiospampinato) I can reproduce the problem as stated at the beginning of this issue. with the data to fix keystrokes to not appear lost but there is a double rendering
of "placeholder" as shown in Fabio Spampinato (@fabiospampinato) 150mS delay new code with no delay
so the terminal is getting the correct characters but it duplication before the keystrokes
are captured by the terminal . as I possibly suspected there is a window where the keystrokes
after the launch terminal are consumed in two places.
bottom line is that I think I've improved things but there is still a vulnerability window
I can try some more experiments but this is difficult for me on OS X
I had thought that the Windows experiments were sufficiently similar - my error in this
Tyriar commentedon Jul 5, 2017
Christopher Leidigh (@cleidigh) the time to input is as small as it can get in a nice way imo, for the OP's case I'd say making an extension to drive the terminal would be a much more reliable way of scripting VS Code.
cleidigh commentedon Jul 5, 2017
Daniel Imms (@Tyriar)
I tend to agree, you can't change code state machine instantly without making a lot of other things
not work well.
I just feel badly this helps Windows more than OS X
Tyriar commentedon Jul 5, 2017
Christopher Leidigh (@cleidigh) well I can definitely notice the difference on macOS as well 👍
cleidigh commentedon Jul 5, 2017
Daniel Imms (@Tyriar)
I just had someone help me doing direct keyboard Control (on my OS X machine eliminating Dragon)
as far as I can tell there is duplicate rendering but the terminal only processes the correct keystrokes.
this may actually be related to what I mentioned about duplicate Windows terminal startup headers.
will try some more experiments
fabiospampinato commentedon Jul 13, 2017
Daniel Imms (@Tyriar) I took your advice and built an extension for this use case. I think it came out pretty nice, I hope this will be useful for somebody else as well.
Tyriar commentedon Jul 13, 2017
Fabio Spampinato (@fabiospampinato) that's really cool! I'm going to share it with the team and in #20013
Merge pull request microsoft#30106 from cleidigh/terminal-q/imp