Closed DiamondYuan closed 5 years ago
function generateAppleScript(dir) {
const terminalCommand = `tell application "Terminal"
do script "cd ${dir}" in front window
end tell`.split('\n').map(line => (` -e '${line.trim()}'`)).join('');
const iTermCommand = `tell application "iTerm"
tell current session of current window
write text "cd ${dir}"
end tell
end tell`.split('\n').map(line => (` -e '${line.trim()}'`)).join('');
const currentApp = `tell application "System Events"
set activeApp to name of first application process whose frontmost is true
end tell`.split('\n').map(line => (` -e '${line.trim()}'`)).join('');
return `[ \`osascript ${currentApp}\` = "Terminal" ] && osascript ${terminalCommand} >/dev/null || osascript ${iTermCommand}`;
}
console.log(generateAppleScript("~"))
把 iTerm 改成 xxx 后 在 Terminal 下 没有报错。那应该是没问题了。
function generateAppleScript(dir) {
const terminalCommand = `tell application "Terminal"
do script "cd ${dir}" in front window
end tell`.split('\n').map(line => (` -e '${line.trim()}'`)).join('');
const iTermCommand = `tell application "xxxx"
tell current session of current window
write text "cd ${dir}"
end tell
end tell`.split('\n').map(line => (` -e '${line.trim()}'`)).join('');
const currentApp = `tell application "System Events"
set activeApp to name of first application process whose frontmost is true
end tell`.split('\n').map(line => (` -e '${line.trim()}'`)).join('');
return `[ \`osascript ${currentApp}\` = "Terminal" ] && osascript ${terminalCommand} >/dev/null || osascript ${iTermCommand}`;
}
console.log(generateAppleScript("~"))
Codecov Report
100% <ø> (ø)
Continue to review full report at Codecov.