牙叔教程简单易懂 目标 用autojs执行shell脚本,脚本所在目录为datalocaltmp 缘起 做息屏运行脚本,要用到类似的方法, 比如息屏使用adb去调用dex文件,来达到息屏效果, 两者相同的地方是 都要复制文件到datalocaltmp文件夹下都要修改权限,命令为chmod777filename或者chmodxfilename 环境 手机:Mi8 Android版本:10 Autojs版本:9。0。10 代码讲解 1。复制文件到datalocaltmp cmdcpsdcardyashu。shdatalocaltmpyashu。sh;rshell(cmd);log(r);ShellResult{code1,errorcp:datalocaltmpyashu。sh:Permissiondenied,result} 非常不幸,没有权限,复制文件失败, 所以我们需要要提高权限,Shizuku可以提升我们的权限到adb级别, Shizuku的使用请查阅上一篇教程,激活Shizuku 将权限提升为adb级别之后,我们重新复制文件 首先,检查有没有adb权限 letadbCheckshell。checkAccess(adb);if(!adbCheck){console。log(没有adb权限,请先使用shizuku激活autojs的adb权限);exit();}else{console。log(已有adb权限);} 复制文件 shell。setDefaultOptions({adb:true});cmdcpsdcardyashu。shdatalocaltmpyashu。sh;rshell(cmd);log(r);ShellResult{code0,error,result} 查看文件yashu。sh权限 shell。setDefaultOptions({adb:true});cmdlsaldatalocaltmpyashu。sh;rshell(cmd);log(r);ShellResult{code0,error,resultrwrw1shellshell842021101517:43datalocaltmpyashu。sh} 可以看到权限是rwrw,没有执行权限,接下来,我们就添加执行权限 2。添加执行权限 shell。setDefaultOptions({adb:true});cmdchmodxdatalocaltmpyashu。sh;rshell(cmd);log(r);ShellResult{code0,error,result} code0,0表示没有发生错误,没有错误就意味着,命令正常执行, 再次查看文件yashu。sh权限 shell。setDefaultOptions({adb:true});cmdlsaldatalocaltmpyashu。sh;rshell(cmd);log(r);ShellResult{code0,error,resultrwxrwxx1shellshell842021101517:46datalocaltmpyashu。sh} 可以看到权限是rwxrwxx,有了执行权限,接下来,我们就执行这个shell脚本 3。执行shell脚本 shell脚本内容 !binbashecho牙叔教程简单易懂author牙叔echo作者:author 执行shell脚本的命令 shell。setDefaultOptions({adb:true});cmdshdatalocaltmpyashu。sh;rshell(cmd);log(r);ShellResult{code0,error,result牙叔教程简单易懂作者:牙叔} 备注 息屏运行脚本使用到的命令与执行shell脚本类似,这也是我写这篇教程的原因, 方便以后复制黏贴 名人名言 思路是最重要的,其他的百度,bing,stackoverflow,github,安卓文档,autojs文档,最后才是群里问问 牙叔教程 声明 部分内容来自网络 本教程仅用于学习,禁止用于其他用途