Guest User

Untitled

a guest
Nov 7th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. // variables
  2. const useImage = true;
  3. let renderContact = false;
  4. const contactFontSize = 21;
  5. const contact = {
  6. name : "John Doe",
  7. tel: "0123456789"
  8. }
  9.  
  10. // Filemanagement
  11. var base_path = "/var/mobile/Library/Mobile Documents/iCloud~dk~simonbs~Scriptable/Documents/weather/";
  12. var fm = FileManager.iCloud();
  13. const filename = Script.name() + ".jpg"
  14. const files = FileManager.local();
  15. const dir = files.documentsDirectory();
  16. const path = files.joinPath(dir, filename)
  17. let fileExists = files.fileExists(path)
  18.  
  19. // create Widget
  20. const widget = new ListWidget()
  21.  
  22. if(useImage){
  23. if(!config.runsInWidget){
  24. let img = await Photos.fromLibrary();
  25. await files.writeImage(path, img);
  26. fileExists = files.fileExists(path);
  27. }
  28. if(fileExists){
  29. widget.backgroundImage = files.readImage(path)
  30. }
  31. }
  32. else {
  33. renderContact = true;
  34. }
  35.  
  36. if(fileExists && !useImage){
  37. files.remove(path);
  38. }
  39.  
  40. if(renderContact && contact.name){
  41. const gradient = new LinearGradient();
  42. gradient.locations = [0, 1];
  43. gradient.colors = [
  44. new Color("00000000"),
  45. new Color("000000aa"),
  46. ];
  47. widget.backgroundGradient = gradient;
  48.  
  49. widget.addSpacer();
  50. const contactBox = widget.addText(contact.name);
  51. contactBox.textColor = Color.white();
  52. contactBox.font = Font.mediumSystemFont(contactFontSize);
  53. }
  54.  
  55. if(contact.tel){
  56. widget.url = `tel://${contact.tel}`;
  57. }
  58.  
  59. Script.setWidget(widget);
  60. widget.presentMedium();
  61.  
  62.  
  63. Script.complete();
Advertisement
Add Comment
Please, Sign In to add comment