아래 terminal
스크립트가 주어지면 AppleScript에서 열린 특정 창 을 대상으로 지정osascript
하는 대신 front window
I를 대상으로 지정 하도록 수정하고 싶습니다 .
terminal
:
#!/bin/bash
# Usage:
# terminal [CMD] Open a new terminal window and execute CMD
#
# Example:
# terminal cd "sleep 100"
terminal() {
# Mac OS only
[ "$(uname -s)" != "Darwin" ] && {
echo 'Mac OS Only'
return
}
local cmd=""
local args="$*"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -n "$args" ]; then
cmd="$args"
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
osascript <<EOF
tell application "Terminal" to tell the front window
set w to do script "$cmd"
repeat
delay 1
if not busy of w then exit repeat
end repeat
close it
end tell
EOF
}
terminal "$@"
현재,를 사용하기 때문에 front window
창이 다른 터미널 창으로 팝업 된 후 포커스를 변경할 수 있습니다. 그러면 do script
작업이 완료되면 close it
실제로 do script
.
내가 염두에 둔 한 가지 아이디어는 AppleScript를 수정 window id
하여 아래와 같이 AppleScript에서 생성 된 창을 가져 오는 것 입니다. 그러나 close W
작동하지 않습니다.
tell application "Terminal"
set W to do script ""
activate
set S to do script "sleep 5" in W
repeat
delay 1
if not busy of S then exit repeat
end repeat
close W
end tell
이 stackexchange 답변 을 기반으로 창 개체를 저장 한 다음 반복 할 수 있습니다.
그런 다음 포커스 여부에 관계없이 연 창을 닫을 수 있습니다.
osascript <<EOF
tell application "Terminal"
set newTab to do script
set current settings of newTab to settings set "Grass"
set theWindow to first window of (every window whose tabs contains newTab)
do script "$cmd" in newTab
repeat
delay 0.05
if not busy of newTab then exit repeat
end repeat
repeat with i from 1 to the count of theWindow's tabs
if item i of theWindow's tabs is newTab then close theWindow
end repeat
end tell
EOF
set current settings of newTab to settings set "Grass"
라인이 필요하지 않습니다 - 그것은 다른 색으로 관련 창을 표시하는 전용입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다