需求场景
利用Mac中的脚本编辑器实现从连接的Android设备中获取指定的文件。
环境
- macOS Monterey 版本 12.7.1
- 脚本编辑器
- adb环境(如果没有的话,可以网上搜下Mac配置adb)
实现方案
1、打开脚本编辑器;
2、新建一个脚本文件;
3、在脚步中增加以下内容
set adbPath to "/Users/wuang/Library/Android/sdk/platform-tools/adb"set sdcardText to "请输入要获取的文件路径:"
set defaultSdcardPath to "/sdcard/"
set sdcardPath to (display dialog sdcardText default answer defaultSdcardPath buttons {"取消", "确定"} default button 2 with icon note)if button returned of sdcardPath is equal to "确定" thenset sdcardPath to (text returned of sdcardPath)-- 获取当前日期set currentDate to current dateset yearStr to year of currentDate as textset monthNum to month of currentDate as integerset dayStr to day of currentDate as textset formattedDate to yearStr & "-" & (monthNum as text) & "-" & dayStr-- 构建目标路径set targetFolder to "~/Downloads/" & formattedDate & "/"-- 创建目录,如果目录已经存在,并不会影响原来目录中的文件;do shell script "mkdir -p " & targetFolderset adbCommand to adbPath & " pull " & sdcardPath & " " & targetFolderdo shell script adbCommand-- end if
end if
4、保存的时候可以选择文件格式;
5、保存为APP后,可以直接双击打开,效果如下: