User Tools

Site Tools


script_external_editor_script_importer

**This is an old revision of the document!** ----

A PCRE internal error occured. This might be caused by a faulty plugin

====== About the script ====== * Purpose: automatically import .js files elsewhere on your device into lightning launcher when they have changed. This allows you to use external script editors! * Author: cdfa * Version: 1.2 * Link: https://plus.google.com/100430440392224314007/posts/KAoKQ317trG ======Changelog===== * fixed importing of large scripts * updated to new api ====== How to use the script ====== Recommended to run the script on resumed event of the container which is your test environment, but you can use it really anytime anywhere. ====== Script code ====== <sxh javascript> var scriptFolder = "/storage/sdcard0/LightningLauncher/script"; var importPath = "/"; bindClass("java.io.FileReader") bindClass("java.io.BufferedReader") bindClass("java.io.File") bindClass("java.lang.StringBuilder") bindClass("android.widget.Toast") var context = getActiveScreen().getContext(); function read(filePath){ try{ var r=new BufferedReader(new FileReader(filePath)); var s= new StringBuilder() ; var l; while((l=r.readLine())!=null)s.append(l+"\n"); return s; }catch(e){ alert(e) return ""; } } //var scriptNames = [] var time = new Date().getTime(); var updatedScripts = []; var folder = new File(scriptFolder) var files = folder.listFiles() if(!files)return; for(i=0;i<files.length;i++){ var fileName = files[i].getName() var length = fileName.length if(fileName.substring(length-3,length)==".js"){ var name = fileName.slice(0,-3); var script=getScriptByName(name); if(script==null){ Toast.makeText(context, "creating new script: "+name, Toast.LENGTH_SHORT).show(); script = createScript(name,"",0,importPath); var tagdate=0; }else{ var tagdate = script.getTag("lmdate"); } var lmdate = files[i].lastModified() if(lmdate>tagdate||typeof tagdate == "undefined"){ updatedScripts.push(name); script.setText(read(scriptFolder+"/"+fileName)); script.setTag("lmdate",time) } } } if( updatedScripts.length>0)Toast.makeText(context, "Updated scripts: "+JSON.stringify( updatedScripts), Toast.LENGTH_SHORT).show(); </sxh>

script_external_editor_script_importer.1476787862.txt.gz · Last modified: 2016/10/18 10:51 by cdfa