อัปเดต:ใหม่กว่า iTerm ต้องการให้คุณเปลี่ยนไวยากรณ์ดังนั้นจะมีลักษณะดังนี้:
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
ดูเพิ่มเติมคำตอบได้ที่นี่
สำหรับ iTerm เวอร์ชั่นเก่า:
รับสคริปต์จากคำตอบของฉันที่นี่คุณสามารถทำสิ่งนี้:
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
}
เพื่ออธิบายสิ่งที่เกิดขึ้น:
เราสร้างชื่อฟังก์ชั่นของเชลล์launchเพื่อให้คุณสามารถใส่สิ่งนี้ในของคุณ~/.bash_profileหรือทุกที่ที่คุณต้องการให้มันทำงานเมื่อเริ่มต้น
เราห่วงมากกว่าผลมาจากการขยายตัวรั้งทุบตี~/folderA{1..5}ซึ่งจะช่วยให้คุณผ่าน~/folderA1~/folderA5
เราเรียกไลบรารี iTerm2 AppleScript ผ่านosascriptเพื่อสร้างแท็บใหม่เปิดใช้งานเรียกใช้เซสชันเริ่มต้นและcdไปยังไดเรกทอรีที่ระบุ