Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // variables
- const useImage = true;
- let renderContact = false;
- const contactFontSize = 21;
- const contact = {
- name : "John Doe",
- tel: "0123456789"
- }
- // Filemanagement
- var base_path = "/var/mobile/Library/Mobile Documents/iCloud~dk~simonbs~Scriptable/Documents/weather/";
- var fm = FileManager.iCloud();
- const filename = Script.name() + ".jpg"
- const files = FileManager.local();
- const dir = files.documentsDirectory();
- const path = files.joinPath(dir, filename)
- let fileExists = files.fileExists(path)
- // create Widget
- const widget = new ListWidget()
- if(useImage){
- if(!config.runsInWidget){
- let img = await Photos.fromLibrary();
- await files.writeImage(path, img);
- fileExists = files.fileExists(path);
- }
- if(fileExists){
- widget.backgroundImage = files.readImage(path)
- }
- }
- else {
- renderContact = true;
- }
- if(fileExists && !useImage){
- files.remove(path);
- }
- if(renderContact && contact.name){
- const gradient = new LinearGradient();
- gradient.locations = [0, 1];
- gradient.colors = [
- new Color("00000000"),
- new Color("000000aa"),
- ];
- widget.backgroundGradient = gradient;
- widget.addSpacer();
- const contactBox = widget.addText(contact.name);
- contactBox.textColor = Color.white();
- contactBox.font = Font.mediumSystemFont(contactFontSize);
- }
- if(contact.tel){
- widget.url = `tel://${contact.tel}`;
- }
- Script.setWidget(widget);
- widget.presentMedium();
- Script.complete();
Advertisement
Add Comment
Please, Sign In to add comment