Files
raycast/sh/open-directory-iterm.sh

55 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Open Directory in iTerm
# @raycast.mode compact
# Optional parameters:
# @raycast.icon 🤖
# @raycast.packageName @kevisual/raycast
# Documentation:
# @raycast.description Open Finder current path in iTerm
# @raycast.author abearxiong
# @raycast.authorURL https://raycast.com/abearxiong
# 获取访达当前窗口路径
finder_path=$(osascript <<EOF
tell application "Finder"
try
set thePath to POSIX path of (target of front window as alias)
return thePath
on error
return ""
end try
end tell
EOF
)
if [[ -z "$finder_path" ]]; then
echo "没有检测到访达窗口"
exit 1
fi
# 用 iTerm 打开文件夹
osascript <<EOF
tell application "iTerm"
activate
try
set newWindow to (create window with default profile)
tell newWindow
tell current session
write text "cd \"$finder_path\""
end tell
end tell
on error
tell current window
create tab with default profile
tell current session
write text "cd \"$finder_path\""
end tell
end tell
end try
end tell
EOF