Два нижеприведенных сценария обрабатывают общие сценарии:
1) Если терминал уже запущен, откройте новое окно терминала и запустите там «cd mydir»
2) Если терминалеще не запущен, используйте начальное окно, которое порождает Терминал (окно 0), вместо того, чтобы досадно запускать второе окно
ПРИМЕЧАНИЕ: что не совсем идеально, если в Терминале открыто несколько окон, все они будут выведенына передний план, перекрывая любые другие приложения.Похоже, что решение для поднятия только последнего окна терминала впереди требует черной магии AppleScriptObjC - ссылки ниже:
https://apple.stackexchange.com/questions/39204/script-to-raise-a-single-window-to-the-front http://tom.scogland.com/blog/2013/06/08/mac-raise-window-by-title/
Скрипт 1- откройте текстовый редактор и сохраните как:
/ usr / local / bin / terminal-here.sh
#!/bin/sh
osascript `dirname $0`/terminal-here.scpt $1 > /dev/null 2> /dev/null
Script 2 - open 'AppleScript Editor ', вставьте содержимое ниже и сохраните как:
/ usr / local / bin / terminal-here.scpt
# AppleScript to cd (change directory) to a path passed as an argument
# If Terminal.app is running, the script will open a new window and cd to the path
# If Terminal.app is NOT running, we'll use the window that Terminal opens automatically on launch
# Run script with passed arguments (if any)
on run argv
if (count of argv) > 0 then
# There was an argument passed so consider it to be the path
set mypath to item 1 of argv
else
# Since no argument was passed, default to the home directory
set mypath to "~"
end if
tell application "System Events"
if (count (processes whose bundle identifier is "com.apple.Terminal")) is 0 then
# Terminal isn't running so we'll make sure to run the 'cd' in Terminal's first window (0)
tell application "/Applications/Utilities/Terminal.app"
# Turn off echo, run the 'cd', clear screen, empty the scrollback, re-enable echo
do script "stty -echo; cd " & (mypath as text) & ";clear; printf \"\\e[3J\"; stty echo" in window 0
activate last window
end tell
else
# Terminal is already running so we'll let it open a new window for our 'cd' command
tell application "/Applications/Utilities/Terminal.app"
# Turn off echo, run the 'cd', clear screen, empty the scrollback, re-enable echo
do script "stty -echo; cd " & (mypath as text) & ";clear; printf \"\\e[3J\"; stty echo"
activate last window
end tell
end if
end tell
end run