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.1 * Link: https://plus.google.com/100430440392224314007/posts/KAoKQ317trG ======Changelog===== * added ability to create scripts for .js files that aren't in LL yet * updated toasts ====== 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 ====== <code> var scriptFolder = "/storage/sdcard0/LightningLauncher/script"; LL.bindClass("java.lang.StringBuilder") LL.bindClass("java.io.FileReader") LL.bindClass("java.io.BufferedReader") LL.bindClass("java.io.File") LL.bindClass("java.text.SimpleDateFormat") LL.bindClass("android.widget.Toast") scriptNames = [] folder = new File(scriptFolder) files = folder.listFiles() for(i=0;i<files.length;i++){ var name = files[i].getName() var length = name.length if(name.substring(length-3,length)==".js"){ scriptNames.push(name.substring(0,length-3)); } } var date = new Date() var time = date.getTime(); var updatedScripts = []; for(i=0;i<scriptNames.length;i++){ //alert(scriptNames[i]) var script=LL.getScriptByName(scriptNames[i]); if(script==null){ Toast.makeText(LL.getContext() , "creating new script: "+scriptNames[i], Toast.LENGTH_SHORT).show(); script = LL.createScript(scriptNames[i],"",0); var tagdate=0; }else{ var tagdate = script.getTag("lmdate"); } file = new File(scriptFolder,scriptNames[i]+".js") lmdate = file.lastModified() if(lmdate>tagdate||typeof tagdate == "undefined"){ updatedScripts.push(scriptNames[i]); text = new StringBuilder(); //try { br = new BufferedReader(new FileReader(file)); var line; while ((line = br.readLine()) != null) { text.append(line); text.append('\n'); } br.close(); script.setText(text); script.setTag("lmdate",time) //}catch (err) { //throw(err) //} } } if( updatedScripts.length>0)Toast.makeText( LL.getContext(), "Updated scripts: "+JSON.stringify( updatedScripts), Toast.LENGTH_SHORT).show(); </code> <sxh javascript> var scriptFolder = "/storage/sdcard0/LightningLauncher/script"; LL.bindClass("java.lang.StringBuilder") LL.bindClass("java.io.FileReader") LL.bindClass("java.io.BufferedReader") LL.bindClass("java.io.File") LL.bindClass("java.text.SimpleDateFormat") LL.bindClass("android.widget.Toast") scriptNames = [] folder = new File(scriptFolder) files = folder.listFiles() for(i=0;i<files.length;i++){ var name = files[i].getName() var length = name.length if(name.substring(length-3,length)==".js"){ scriptNames.push(name.substring(0,length-3)); } } var date = new Date() var time = date.getTime(); var updatedScripts = []; for(i=0;i<scriptNames.length;i++){ //alert(scriptNames[i]) var script=LL.getScriptByName(scriptNames[i]); if(script==null){ Toast.makeText(LL.getContext() , "creating new script: "+scriptNames[i], Toast.LENGTH_SHORT).show(); script = LL.createScript(scriptNames[i],"",0); var tagdate=0; }else{ var tagdate = script.getTag("lmdate"); } file = new File(scriptFolder,scriptNames[i]+".js") lmdate = file.lastModified() if(lmdate>tagdate||typeof tagdate == "undefined"){ updatedScripts.push(scriptNames[i]); text = new StringBuilder(); //try { br = new BufferedReader(new FileReader(file)); var line; while ((line = br.readLine()) != null) { text.append(line); text.append('\n'); } br.close(); script.setText(text); script.setTag("lmdate",time) //}catch (err) { //throw(err) //} } } if( updatedScripts.length>0)Toast.makeText( LL.getContext(), "Updated scripts: "+JSON.stringify( updatedScripts), Toast.LENGTH_SHORT).show(); </sxh>

script_external_editor_script_importer.1454151964.txt.gz · Last modified: 2016/01/30 11:06 by cdfa