Skip to content

Commit ef4ad4d

Browse files
committed
fix some iTerm related timing issue
1 parent 109ae65 commit ef4ad4d

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Term Window/DTTermWindowController.m

+10-6
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,18 @@ - (IBAction)executeCommandInTerminal:(id) __unused sender {
240240

241241
// test for iTerms newer scripting bridge
242242
if(iTerm && [iTerm respondsToSelector:@selector(createWindowWithDefaultProfileCommand:)]) {
243-
iTerm2Window *terminal = nil;
244-
iTerm2Session *session = nil;
243+
iTerm2Window *window = [iTerm createWindowWithDefaultProfileCommand:nil];
244+
iTerm2Session *session = [window currentSession];
245245

246-
if([iTerm isRunning]) {
247-
[iTerm createWindowWithDefaultProfileCommand:nil];
246+
int cnt = 0;
247+
while ([[session text] length] == 0) {
248+
if ( cnt++ > 100 ) {
249+
NSLog(@"timeout reached");
250+
break;
251+
}
252+
NSLog(@"wait for prompt...");
253+
[NSThread sleepForTimeInterval:0.01f];
248254
}
249-
terminal = [iTerm valueForKey:@"currentWindow"];
250-
session = [terminal valueForKey:@"currentSession"];
251255

252256
// write text "cd ~/whatever"
253257
[session writeContentsOfFile:nil text:cdCommandString newline:true];

0 commit comments

Comments
 (0)