├── .gitignore ├── img.png ├── img_1.png ├── img_2.png ├── telegram_clone_without_tag.sh ├── telegram_clone_with_tag.sh └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea -------------------------------------------------------------------------------- /img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/11001100111011101110001/Mac_Telegram_Clone/HEAD/img.png -------------------------------------------------------------------------------- /img_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/11001100111011101110001/Mac_Telegram_Clone/HEAD/img_1.png -------------------------------------------------------------------------------- /img_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/11001100111011101110001/Mac_Telegram_Clone/HEAD/img_2.png -------------------------------------------------------------------------------- /telegram_clone_without_tag.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 检查是否提供了参数,参数一:开始数字;参数二:结束数字 4 | if [ -z "$1" ] || [ -z "$2" ]; then 5 | echo "Usage: $0 " 6 | exit 1 7 | fi 8 | 9 | # 获取传入的数字参数 10 | START=$1 11 | END=$2 12 | 13 | # 定义 telegram_clone 目录 14 | TELEGRAM_CLONE_DIR="$HOME/telegram_clone" 15 | 16 | # 检查 telegram_clone 目录是否存在 17 | if [ ! -d "$TELEGRAM_CLONE_DIR" ]; then 18 | mkdir "$TELEGRAM_CLONE_DIR" 19 | echo "Created directory $TELEGRAM_CLONE_DIR." 20 | else 21 | echo "Directory $TELEGRAM_CLONE_DIR already exists. Skipping creation." 22 | fi 23 | 24 | # 循环创建子文件夹 25 | for (( i=START; i<=END; i++ )) 26 | do 27 | SUBDIR="$TELEGRAM_CLONE_DIR/$i" 28 | if [ -d "$SUBDIR" ]; then 29 | echo "Directory $SUBDIR already exists. Skipping." 30 | else 31 | mkdir "$SUBDIR" 32 | echo "Created directory $SUBDIR." 33 | fi 34 | 35 | # 运行 Telegram 命令 36 | nohup /Applications/Telegram.app/Contents/MacOS/Telegram -workdir "$SUBDIR" > /dev/null 2>&1 & 37 | echo "Started Telegram instance in $SUBDIR." 38 | done -------------------------------------------------------------------------------- /telegram_clone_with_tag.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 创建 TG 分身函数 4 | create_tg() { 5 | local num1="$1" 6 | 7 | APP_CLONE="$APP_TELEGRAM_CLONE_DIR/Telegram_$1.app" 8 | if [ -d "$APP_CLONE" ]; then 9 | echo "Directory $APP_CLONE already exists. Skipping." 10 | else 11 | cp -R /Applications/Telegram.app $APP_CLONE 12 | echo "Created directory $APP_CLONE." 13 | fi 14 | 15 | SUBDIR="$TELEGRAM_CLONE_DIR/$1" 16 | if [ -d "$SUBDIR" ]; then 17 | echo "Directory $SUBDIR already exists. Skipping." 18 | else 19 | mkdir "$SUBDIR" 20 | echo "Created directory $SUBDIR." 21 | fi 22 | 23 | # 运行 Telegram 命令 24 | nohup "$APP_TELEGRAM_CLONE_DIR/Telegram_$1.app/Contents/MacOS/Telegram" -workdir "$SUBDIR" > /dev/null 2>&1 & 25 | echo "Started Telegram instance in $SUBDIR." 26 | } 27 | 28 | 29 | # 解析参数,start 代表开始 TG Tag,end 代表结束 TG Tag,tag_num 代表分别开启哪些 TG Tag 30 | while [[ "$#" -gt 0 ]]; do 31 | case $1 in 32 | --start) shift; start="$1";; 33 | --end) shift; end="$1";; 34 | --tag_num) shift; while [[ "$#" -gt 0 && ! "$1" =~ ^-- ]]; do tag_num+=("$1"); shift; done;; 35 | *) echo "Unknown parameter passed: $1"; exit 1;; 36 | esac 37 | shift 38 | done 39 | 40 | # start 参数和 end 参数必须成对出现 41 | if [[ -n "$start" && -z "$end" ]]; then 42 | echo "Error: The --start parameter and the --end parameter must both be present." 43 | exit 1 44 | fi 45 | 46 | # tag_num 参数不能和 start/end 参数一起出现 47 | if [[ -n "$start" && -n "$end" && ${#tag_num[@]} -gt 0 ]]; then 48 | echo "Error: --tag_num parameter cannot be used when both --start and --end are specified." 49 | exit 1 50 | fi 51 | 52 | # 定义 /Applications 下的分身目录 53 | APP_TELEGRAM_CLONE_DIR="/Applications/TelegramClone" 54 | 55 | # 检查 TelegramClone 分身目录是否存在 56 | if [ ! -d "$APP_TELEGRAM_CLONE_DIR" ]; then 57 | mkdir "$APP_TELEGRAM_CLONE_DIR" 58 | echo "Created directory $APP_TELEGRAM_CLONE_DIR." 59 | else 60 | echo "Directory $APP_TELEGRAM_CLONE_DIR already exists. Skipping creation." 61 | fi 62 | 63 | # 定义 telegram_clone 数据目录 64 | TELEGRAM_CLONE_DIR="$HOME/telegram_clone" 65 | 66 | # 检查 telegram_clone 目录是否存在 67 | if [ ! -d "$TELEGRAM_CLONE_DIR" ]; then 68 | mkdir "$TELEGRAM_CLONE_DIR" 69 | echo "Created directory $TELEGRAM_CLONE_DIR." 70 | else 71 | echo "Directory $TELEGRAM_CLONE_DIR already exists. Skipping creation." 72 | fi 73 | 74 | # 处理 tag_num 参数中的每个数字 75 | if [[ ${#tag_num[@]} -gt 0 ]]; then 76 | for num in "${tag_num[@]}"; do 77 | create_tg $num; 78 | done 79 | fi 80 | 81 | # 循环创建 Telegram 分身和 Telegram 数据子文件夹 82 | if [[ -n "$start" ]]; then 83 | for (( i=$start; i<=$end; i++ )); do 84 | create_tg $i; 85 | done 86 | fi -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 在 Mac 上多开 Telegram 教程 2 | 3 | > 该教程只对 Mac Telegram 桌面版有效 4 | 5 | ## 实现原理 6 | 7 | > 利用 Telegram 官方桌面版的 `-workdir` 指定工作目录来运行多个 Telegram 实例 8 | 9 | ## 预览图 10 | ![img.png](img.png) 11 | 12 | ## 创建单个 Telegram 分身(非必要步骤,批量创建脚本在下一节) 13 | 14 | ```shell 15 | # Telegram 安装路径 -workdir 用户路径 16 | nohup /Applications/Telegram.app/Contents/MacOS/Telegram -workdir /User/path > /dev/null 2>&1 & 17 | ``` 18 | 19 | 注意:`/User/path` 指的是分身工作目录,需要提前建立好,并且有操作权限,建议建在家目录下。 20 | 21 | ### 使用教程 22 | 23 | 1. 下载 Telegram 桌面版并安装,默认安装路径 `/Applications/Telegram.app`,如果系统中存在多个 Telegram 版本,需要根据实际情况进行微调。 24 | 2. 打开 Mac 终端,快捷键 `command + 空格` 搜索终端。 25 | ![img_2.png](img_2.png) 26 | 27 | 3. 运行以下命令 28 | 29 | ```shell 30 | # 建立分身数据存储文件夹(也可以起别的名字,随意) 31 | mkdir telegram_clone 32 | 33 | # 进入 telegram_clone 34 | cd telegram_clone 35 | 36 | # 创建子文件夹(也可以起别的名字,随意) 37 | mkdir 100 38 | 39 | # 创建 Telegram 分身,基础语法: `Telegram 安装路径` -workdir `用户路径` 40 | nohup /Applications/Telegram.app/Contents/MacOS/Telegram -workdir /User/path/telegram_clone/100 > /dev/null 2>&1 & 41 | ``` 42 | 43 | _**需要注意的是,下次启动时,也需要用同样的命令启动,直接点击图标是无法指定用户路径的。**_ 44 | 45 | 46 | ## 批量创建和运行 Telegram 多个分身 47 | 48 | > 批量脚本分为 2 个版本 49 | 50 | ### Tag 版本(telegram_clone_with_tag.sh) 51 | 52 | > 适合需要创建很多分身的家人,例如 10 个以上 53 | 54 | + 优点:会对分身进行编号,可以很方便的区分每个分身 55 | + 缺点:会占用多余的硬盘空间,因为对分身编号需要将 Telegram 复制多份,为了美观,分身会统一存储在 `/Applications/TelegramClone` 路径中。 56 | 57 | ![img_1.png](img_1.png) 58 | 59 | #### 使用教程 60 | 61 | 1. 下载 Telegram 桌面版,并安装,默认安装路径 `/Applications/Telegram.app`,如果有其他版本的 Telegram 占用了该路径,先卸载避免产生冲突。安装完桌面版后,可以再安装其他版本的 TG。 62 | 2. 打开 Mac 终端,运行以下命令。 63 | 64 | ```shell 65 | # 下载批量脚本 66 | git cloen https://github.com/11001100111011101110001/Mac_Telegram_Clone.git 67 | 68 | # 进入脚本目录 69 | cd Mac_Telegram_Clone 70 | 71 | # 赋予执行权限,with_tag 脚本会对分身进行编号,without_tag 不会 72 | chmod +x telegram_clone_with_tag.sh 73 | 74 | # 创建/运行分身,--start 是开始编号,--end 是结束编号,--tag_num 是创建/运行指定编号分身 75 | ./telegram_clone_with_tag.sh --start 1 --end 10 # 创建/运行编号为 1-10 的 TG 分身 76 | ./telegram_clone_with_tag.sh --tag_num 10 15 18 # 创建/运行编号为 10 15 18 的 TG 分身 77 | ``` 78 | 79 | ### 无 Tag 版本(telegram_clone_without_tag.sh) 80 | 81 | > 适合无需创建太多分身和无需对分身进行编号管理的家人 82 | 83 | + 优点:清爽,不会占用多余的硬盘空间。 84 | + 缺点:无法对分身进行编号,大家都长一样,分身多了之后容易分不清。 85 | 86 | #### 使用教程 87 | 88 | ```shell 89 | # 下载批量脚本 90 | git cloen https://github.com/11001100111011101110001/Mac_Telegram_Clone.git 91 | 92 | # 进入脚本目录 93 | cd Mac_Telegram_Clone 94 | 95 | # 赋予执行权限,with_tag 脚本会对分身进行显性编号;without_tag 不会,需要家人自己记录对应关系。 96 | chmod +x telegram_clone_without_tag.sh 97 | 98 | # 创建/运行分身,第一个参数代表开始编号,第二个参数代表结束编号 99 | ./telegram_clone_without_tag.sh 1 10 # 创建/运行编号为 1-10 的 TG 分身 100 | ``` 101 | 102 | ## 数据存储路径 103 | 104 | ``` 105 | # 分身用户存储路径 106 | /User/path/telegram_clone 107 | 108 | # 分身软件存储路径(只有使用带 tag 版批量多开才会产生此文件夹) 109 | /Applications/TelegramClone 110 | ``` 111 | 112 | _**需要注意的是,下次启动时,需要用命令启动,直接点击图标是无法指定用户路径的。**_ 113 | 114 | ## 关于升级 115 | 116 | > 如果使用的是不带 Tag 的脚本创建的分身,只需要升级主程序即可。如果是带 Tag 的脚本创建的分身,升级了主程序后,将 `/Applications/TelegramClone` 路径下的分身全部删除,重新运行创建分身软件即可。 117 | 118 | ## 版本信息 119 | 120 | + Macbook Pro:M3 Max;64GB 内存 121 | + Telegram 桌面版: 122 | + 版本号:5.3.0 123 | + 下载地址:https://desktop.telegram.org/ 124 | 125 | ## 据不严谨测试 126 | 127 | M3 Max 64 GB 的 Mac 笔记本,可以同时运行 54 个 Telegram 分身,也就是说可以同时运行 54 * 3 = 162 个账号,多了之后新建立的分身会出现画面崩溃的情况,其他机型请自行测试。 128 | 129 | ## 参考资料 130 | 131 | + https://gist.github.com/AleksandrMihhailov/672d4f7ce3321ff2e2994d35117bd316 132 | + https://github.com/telegramdesktop/tdesktop/blob/dev/Telegram/SourceFiles/platform/mac/launcher_mac.mm 133 | --------------------------------------------------------------------------------