Skip to content

Commit

Permalink
fix: fix error when iterm is not installed (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
DiamondYuan authored and popomore committed Dec 20, 2018
1 parent 444dee9 commit cbdd73d
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions lib/command/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,21 @@ class FindCommand extends BaseCommand {
}
/* istanbul ignore next */
generateAppleScript(dir) {
const command =
`tell application "System Events"
set activeApp to name of first application process whose frontmost is true
if "iTerm" is in activeApp then
tell application "iTerm"
tell current session of current window
write text "cd ${dir}"
end tell
end tell
else if "Terminal" is in activeApp then
tell application "Terminal"
do script "cd ${dir}" in front window
end tell
end if
end tell`.split('\n').map(line => (` -e '${line.trim()}'`));
return `osascript ${command.join('')}`;
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}`;
}

* copyPath(repo, dir) {
Expand Down

0 comments on commit cbdd73d

Please sign in to comment.