Cập nhật: iTerm mới hơn yêu cầu bạn thay đổi cú pháp, vì vậy điều này sẽ giống như:
tell application "iTerm"
tell current window
create tab with default profile
end tell
tell current tab of current window
set _new_session to last item of sessions
end tell
tell _new_session
select
write text "cd \"$dir\""
end tell
end tell
Xem thêm câu trả lời này ở đây .
Đối với các phiên bản iTerm cũ hơn:
Lấy kịch bản từ câu trả lời của tôi ở đây , bạn có thể làm một cái gì đó như thế này:
launch () {
for dir in ~/folderA{1..5}; do
/usr/bin/osascript <<-EOF
tell application "iTerm"
make new terminal
tell the current terminal
activate current session
launch session "Default Session"
tell the last session
write text "cd \"$dir\""
end tell
end tell
end tell
EOF
done
}
Để giải thích những gì đang xảy ra:
Chúng tôi tạo một hàm shell có tên launch, vì vậy bạn có thể đặt hàm này vào ~/.bash_profilehoặc bất cứ nơi nào bạn muốn để nó được thực thi khi khởi động.
Chúng tôi lặp lại kết quả của việc mở rộng cú đúp Bash ~/folderA{1..5}, mang lại cho bạn ~/folderA1thông qua ~/folderA5.
Chúng tôi gọi thư viện iTerm2 AppleScript thông qua osascriptđể tạo một tab mới, kích hoạt nó, khởi chạy phiên mặc định và cdđến thư mục được chỉ định.