mac iterm2 使用 lrzsz

前言

mac os 终端不支持使用 rz sz 上传下载文件,本文提供解决方法。

mac 上安装

bash 复制代码
brew install lrzsz

两个脚本

注意:/usr/local/bin/iterm2-send-zmodem.sh 中的 sz命令路径要和你mac 上 sz 命令路径一致。

/usr/local/bin/iterm2-recv-zmodem.sh 中的 rz 命令路径要和你 mac 上的 rz 命令路径一致。

查看 mac 上 rz 和 sz 命令的路径

bash 复制代码
$ which rz
/opt/homebrew/bin/rz
bash 复制代码
$ which sz
/opt/homebrew/bin/sz
bash 复制代码
cat > /usr/local/bin/iterm2-send-zmodem.sh < EOF
#!/bin/bash
# Author: Matt Mastracci (matthew@mastracci.com)
# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
# licensed under cc-wiki with attribution required
# Remainder of script public domain

osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
if [[ $NAME = "iTerm" ]]; then
    FILE=`osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"`
else
    FILE=`osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"`
fi
if [[ $FILE = "" ]]; then
    echo Cancelled.
    # Send ZModem cancel
    echo -e \\x18\\x18\\x18\\x18\\x18
    sleep 1
    echo
    echo \# Cancelled transfer
else
    /opt/homebrew/bin/sz "$FILE" -e -b
    sleep 1
    echo
    echo \# Received $FILE
fi
EOF
bash 复制代码
cat > /usr/local/bin/iterm2-recv-zmodem.sh  << EOF
#!/bin/bash
# Author: Matt Mastracci (matthew@mastracci.com)
# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
# licensed under cc-wiki with attribution required
# Remainder of script public domain

osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
if [[ $NAME = "iTerm" ]]; then
    FILE=`osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose folder with prompt "Choose a folder to place received files in"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"`
else
    FILE=`osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose folder with prompt "Choose a folder to place received files in"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"`
fi

if [[ $FILE = "" ]]; then
    echo Cancelled.
    # Send ZModem cancel
    echo -e \\x18\\x18\\x18\\x18\\x18
    sleep 1
    echo
    echo \# Cancelled transfer
else
    cd "$FILE"
    /opt/homebrew/bin/rz -E -e -b
    sleep 1
    echo
    echo
    echo \# Sent \-\> $FILE
fi
EOF

给脚本赋予权限

bash 复制代码
sudo chmod 777 /usr/local/bin/iterm2-*

配置 iterm2




注意 Action 列有下拉选项框,选择即可。其他列复制粘贴。

为方便复制

bash 复制代码
Regular expression: rz waiting to receive.\*\*B0100
            Action: Run Silent Coprocess
        Parameters: /usr/local/bin/iterm2-send-zmodem.sh
           Instant: checked

Regular expression: \*\*B00000000000000
            Action: Run Silent Coprocess
        Parameters: /usr/local/bin/iterm2-recv-zmodem.sh
           Instant: checked
相关推荐
Macdo_cn5 小时前
My Metronome for Mac v1.4.2 我的节拍器 支持M、Intel芯片
macos·音视频
吹泡泡的派大星6 小时前
从0-1搭建mac环境最新版
macos
zhouwu_linux6 小时前
MT7628基于原厂的SDK包, 修改ra1网卡的MAC方法。
linux·运维·macos
丁总学Java6 小时前
在 macOS 的 ARM 架构上按住 Command (⌘) + Shift + .(点)。这将暂时显示隐藏文件和文件夹。
macos
青木川崎6 小时前
Mac下常用命令
macos
ClaNNEd@6 小时前
Mac端homebrew安装配置
macos·brew
nicekwell7 小时前
macos sequoia 禁用 ctrl+enter 打开鼠标右键菜单功能
macos
丁总学Java11 小时前
在 Mac ARM 架构的 macOS 系统上启用 F1 键作为 Snipaste 的截屏快捷键
macos·snipaste
天下皆白_唯我独黑15 小时前
brew Nushell mac升级版本
macos
刘什么洋啊Zz19 小时前
MacOS下使用Ollama本地构建DeepSeek并使用本地Dify构建AI应用
人工智能·macos·ai·ollama·deepseek