diff --git a/src/vs/workbench/parts/execution/electron-browser/iterm.scpt b/src/vs/workbench/parts/execution/electron-browser/iterm.scpt index d0eb1b96631e9c56984962561273980745e44450..84e068fbddb6e8259b67c22cb111897607cba1d5 100644 --- a/src/vs/workbench/parts/execution/electron-browser/iterm.scpt +++ b/src/vs/workbench/parts/execution/electron-browser/iterm.scpt @@ -1,15 +1,20 @@ +------------------------------------------------------------------- +-- Copyright (c) Microsoft Corporation. All rights reserved. +-- Licensed under the MIT License. +-- See License.txt in the project root for license information. +------------------------------------------------------------------- + on run argv set command to "cd \"" & argv & "\"; clear" as string - + tell application "iTerm" activate + set myterm to (current terminal) tell myterm tell (launch session "Default") write text command end tell end tell - - set done to true end tell end run diff --git a/src/vs/workbench/parts/execution/electron-browser/itermNew.scpt b/src/vs/workbench/parts/execution/electron-browser/itermNew.scpt new file mode 100644 index 0000000000000000000000000000000000000000..ca572682136152a511da1a52581449f49803686e --- /dev/null +++ b/src/vs/workbench/parts/execution/electron-browser/itermNew.scpt @@ -0,0 +1,30 @@ +------------------------------------------------------------------- +-- Copyright (c) Microsoft Corporation. All rights reserved. +-- Licensed under the MIT License. +-- See License.txt in the project root for license information. +------------------------------------------------------------------- + +on run argv + set command to "cd \"" & argv & "\"; clear" as string + + tell application "iTerm" + activate + + set theWindow to current window + + if theWindow = missing value then + set theWindow to (create window with default profile) + tell theWindow + write (current session) text command + end tell + else + tell theWindow + set theTab to (create tab with default profile) + tell theTab + write (current session) text command + end tell + end tell + end if + + end tell +end run diff --git a/src/vs/workbench/parts/execution/electron-browser/macHelper.scpt b/src/vs/workbench/parts/execution/electron-browser/macHelper.scpt index 926c7a962a59781f6a12a6f6eb8c36c3386c6c22..a8fe3b8aa4acf6e6aecbdb95e324ab9e3d30101f 100644 --- a/src/vs/workbench/parts/execution/electron-browser/macHelper.scpt +++ b/src/vs/workbench/parts/execution/electron-browser/macHelper.scpt @@ -1,26 +1,32 @@ +------------------------------------------------------------------- +-- Copyright (c) Microsoft Corporation. All rights reserved. +-- Licensed under the MIT License. +-- See License.txt in the project root for license information. +------------------------------------------------------------------- + on run argv set prevDelimiter to AppleScript's text item delimiters - + set AppleScript's text item delimiters to " " set command to argv as string set AppleScript's text item delimiters to prevDelimiter - + tell application "Terminal" activate - + set targetWindow to null - + repeat with currentWindow in windows if currentWindow is not busy then set targetWindow to currentWindow end if end repeat - + if targetWindow ≠ null then do script command in targetWindow else do script command end if - + end tell end run diff --git a/src/vs/workbench/parts/execution/electron-browser/terminal.scpt b/src/vs/workbench/parts/execution/electron-browser/terminal.scpt index 7c309a02f4583b754889c9579edd884335aa467c..43fc40fdb4c8763e6602622c44428f5fcc1cdd54 100644 --- a/src/vs/workbench/parts/execution/electron-browser/terminal.scpt +++ b/src/vs/workbench/parts/execution/electron-browser/terminal.scpt @@ -1,20 +1,26 @@ -on run argv - set command to "cd \"" & argv & "\"; clear" as string - - tell application "Terminal" - activate - set targetWindow to null - - repeat with currentWindow in windows - if currentWindow is not busy then - set targetWindow to currentWindow - end if - end repeat - - if targetWindow ≠ null then - do script command in targetWindow - else - do script command - end if - end tell -end run +------------------------------------------------------------------- +-- Copyright (c) Microsoft Corporation. All rights reserved. +-- Licensed under the MIT License. +-- See License.txt in the project root for license information. +------------------------------------------------------------------- + +on run argv + set command to "cd \"" & argv & "\"; clear" as string + + tell application "Terminal" + activate + set targetWindow to null + + repeat with currentWindow in windows + if currentWindow is not busy then + set targetWindow to currentWindow + end if + end repeat + + if targetWindow ≠ null then + do script command in targetWindow + else + do script command + end if + end tell +end run diff --git a/src/vs/workbench/parts/execution/electron-browser/terminalService.ts b/src/vs/workbench/parts/execution/electron-browser/terminalService.ts index 1fc0893fcd1b2b966e77214d787e2a1d55bbd58b..2dfb29a687f2fe3bed9cd638a2a085b9baefbcad 100644 --- a/src/vs/workbench/parts/execution/electron-browser/terminalService.ts +++ b/src/vs/workbench/parts/execution/electron-browser/terminalService.ts @@ -44,10 +44,28 @@ export class MacTerminalService implements ITerminalService { } return this._terminalApplicationScriptPath = new TPromise((c, e) => { - let child = cp.spawn('/usr/bin/osascript', ['-e', 'exists application "iTerm"']); + let version = ''; + let child = cp.spawn('/usr/bin/osascript', ['-e', 'item (((exists application "iTerm") as integer) + 1) of {0, version of application "iTerm"}']); child.on('error', e); + child.stdout.on('data', (data) => { + version += data.toString(); + }); child.on('exit', (code: number) => { - c(code === 0 ? 'iterm.scpt' : 'terminal.scpt'); + let script = 'terminal.scpt'; + if (code === 0) { + const match = /(\d+).(\d+).(\d+)/.exec(version); + if (match.length >= 4) { + const major = +match[1]; + const minor = +match[2]; + const veryMinor = +match[3]; + if ((major < 2) || (major === 2 && minor < 9) || (major === 2 && minor === 9 && veryMinor < 20150414)) { + script = 'iterm.scpt'; + } else { + script = 'itermNew.scpt'; // versions >= 2.9.20150414 use new script syntax + } + } + } + c(script); }); }).then(name => uri.parse(require.toUrl(`vs/workbench/parts/execution/electron-browser/${ name }`)).fsPath); }