// To use, add a parameter to the widget with a format of: image.png|padding-top|text-color // The image should be placed in the iCloud Scriptable folder (case-sensitive). // The padding-top spacing parameter moves the text down by a set amount. // The text color parameter should be a hex value. // For example, to use the image bkg_fall.PNG with a padding of 40 and a text color of red, // the parameter should be typed as: bkg_fall.png|40|#ff0000 // All parameters are required and separated with "|" // Parameters allow different settings for multiple widget instances. let widgetHello = new ListWidget(); var today = new Date(); var widgetInputRAW = args.widgetParameter; try { widgetInputRAW.toString(); } catch(e) { throw new Error("Please long press the widget and add a parameter."); } var widgetInput = widgetInputRAW.toString(); var inputArr = widgetInput.split("|"); // iCloud file path var scriptableFilePath = "/var/mobile/Library/Mobile Documents/iCloud~dk~simonbs~Scriptable/Documents/"; var removeSpaces1 = inputArr[0].split(" "); // Remove spaces from file name var removeSpaces2 = removeSpaces1.join(''); var tempPath = removeSpaces2.split("."); var backgroundImageURLRAW = scriptableFilePath + tempPath[0]; var fm = FileManager.iCloud(); var backgroundImageURL = scriptableFilePath + tempPath[0] + "."; var backgroundImageURLInput = scriptableFilePath + removeSpaces2; // For users having trouble with extensions // Uses user-input file path is the file is found // Checks for common file format extensions if the file is not found if (fm.fileExists(backgroundImageURLInput) == false) { var fileTypes = ['png', 'jpg', 'jpeg', 'tiff', 'webp', 'gif']; fileTypes.forEach(function(item) { if (fm.fileExists((backgroundImageURL + item.toLowerCase())) == true) { backgroundImageURL = backgroundImageURLRAW + "." + item.toLowerCase(); } else if (fm.fileExists((backgroundImageURL + item.toUpperCase())) == true) { backgroundImageURL = backgroundImageURLRAW + "." + item.toUpperCase(); } }); } else { backgroundImageURL = scriptableFilePath + removeSpaces2; } var spacing = parseInt(inputArr[1]); /* --------------- */ /* Assemble Widget */ /* --------------- */ //Top spacing widgetHello.addSpacer(parseInt(spacing)); // Bottom Spacer widgetHello.addSpacer(); widgetHello.setPadding(15, 7, 10, 0) // Background image widgetHello.backgroundImage = Image.fromFile(backgroundImageURL); // Set widget Script.setWidget(widgetHello);