当前位置:   article > 正文

自动从Android上拉取指定文件

自动从Android上拉取指定文件

需求场景

利用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 "确定" then
	set sdcardPath to (text returned of sdcardPath)
	-- 获取当前日期
	set currentDate to current date
	set yearStr to year of currentDate as text
	set monthNum to month of currentDate as integer
	set dayStr to day of currentDate as text
	set formattedDate to yearStr & "-" & (monthNum as text) & "-" & dayStr
	
	-- 构建目标路径
	set targetFolder to "~/Downloads/" & formattedDate & "/"
	
	-- 创建目录,如果目录已经存在,并不会影响原来目录中的文件;
	do shell script "mkdir -p " & targetFolder
	
	set adbCommand to adbPath & " pull " & sdcardPath & " " & targetFolder
	do shell script adbCommand
	-- end if
end if
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

4、保存的时候可以选择文件格式;
在这里插入图片描述
5、保存为APP后,可以直接双击打开,效果如下:

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/235671
推荐阅读
相关标签
  

闽ICP备14008679号