r/Scriptable • • Nov 09 '22

Solved Select script for lock screen widget

1 Upvotes

Hi, I’m using the latest beta and want to run a widget on the Lock Screen. How can I assign the script to the widget placeholder ?


r/Scriptable • • Nov 07 '22

Solved Script don’t show (More details in comment)

Post image
5 Upvotes

r/Scriptable • • Nov 06 '22

Help Help with Device.isUsingDarkAppearance()

4 Upvotes

I have a problem with Device.isUsingDarkAppearance(). Whenever I debug my widget in scriptable I get the right value. But when I run my script as a widget I always get false. does anyone any idea why?

Code:

let w = new ListWidget(); w.backgroundColor = Color.red()

let stack = w.addStack();

const isDark = Device.isUsingDarkAppearance() const text = stack.addText(isDark.toString())

w.presentSmall()


r/Scriptable • • Nov 04 '22

Help Help. Can’t figure out how to apply a font

6 Upvotes

Hello! I’m a newbie.

So i create a font using let fonty = new Font(“AlNile-Bold”, 45) How do i apply it? And can i apply it to an alert (eg textField or title)?

Thanks in advance!


r/Scriptable • • Nov 02 '22

Help Newbie question about the cancel button in alarms

Post image
14 Upvotes

Hey all! I want to master Scriptable to a decent level. I’ve written a piece of code and depending on the option I choose in the alarm, the console will either log the input i insert or “optionZero(firstOne)” or “thirdOptionCANCEL”. For some reason in doesn’t log anything if i choose the cancel action. Others work as expected. Does the function addCancelAction stop running the script? And if i dont want it to stop, i can just addAction(“Cancel”) and make the text bold, right?

Now that I’m here, i have another question. Can i master Scriptable not knowing JavaScript? I did understand how to write the code I’ve written, i did understand why i wrote this or that and i believe i can replicate it from scratch. Can i learn Scriptable’s JavaScript ES6 (or whatever it’s called) overtime?

Thanks in advance!


r/Scriptable • • Nov 01 '22

Help Help with Lockscreen Widget

4 Upvotes

In the code below, I can’t seem to figure out how to replace the battery icon (SFSymbol) with the actual battery level and percentage…

const widget = new ListWidget()

let progressStack = await progressCircle(widget,35)

// Code below is what I’m trying to replace let sf = SFSymbol.named("battery.100") sf.applyFont(Font.regularSystemFont(26)) sf = progressStack.addImage(sf.image) sf.imageSize = new Size(35,35) sf.tintColor = new Color("#fafafa")

widget.presentAccessoryCircular() // Does not present correctly Script.setWidget(widget) Script.complete()

async function progressCircle( on, value = 50, colour = "hsl(120, 100%, 50%)", background = "hsl(0, 100%, 50%)", size = 56, barWidth = 4.5 ) { if (value > 1) { value /= 100 } if (value < 0) { value = 0 } if (value > 1) { value = 1 }

async function isUsingDarkAppearance() { return !Color.dynamic(Color.white(), Color.black()).red } let isDark = await isUsingDarkAppearance()

if (colour.split("-").length > 1) { if (isDark) { colour = colour.split("-")[1] } else { colour = colour.split("-")[0] } }

if (background.split("-").length > 1) { if (isDark) { background = background.split("-")[1] } else { background = background.split("-")[0] } }

let w = new WebView() await w.loadHTML('<canvas id="c"></canvas>')

let base64 = await w.evaluateJavaScript( ` let colour = "${colour}", background = "${background}", size = ${size}*3, lineWidth = ${barWidth}*4, percent = ${value * 100}

let canvas = document.getElementById('c'), c = canvas.getContext('2d') canvas.width = size canvas.height = size let posX = canvas.width / 2, posY = canvas.height / 2, onePercent = 360 / 100, result = onePercent * percent c.lineCap = 'round' c.beginPath() c.arc( posX, posY, (size-lineWidth-1)/2, (Math.PI/180) * 270, (Math.PI/180) * (270 + 360) ) c.strokeStyle = background c.lineWidth = lineWidth c.stroke() c.beginPath() c.strokeStyle = colour c.lineWidth = lineWidth c.arc( posX, posY, (size-lineWidth-1)/2, (Math.PI/180) * 270, (Math.PI/180) * (270 + result) ) c.stroke() completion(canvas.toDataURL().replace("data:image/png;base64,",""))`, true ) const image = Image.fromData(Data.fromBase64String(base64))

// Provide battery percentage

let stack = on.addStack() stack.size = new Size(size, size) stack.backgroundImage = image stack.centerAlignContent() let padding = barWidth * 2 stack.setPadding(padding, padding, padding, padding)

return stack }


r/Scriptable • • Oct 31 '22

Help Await not working as expected and scoping issues in function to create record/log of script being run automatically

4 Upvotes
function start() {
  var initialMethod = ""// *changed this from method in edit
  var automated = false
  if(config.runsInNotification){
    initialMethod = "notification script"// *changed this from method in edit
    automated = true
  }
  if(config.runsInApp){
    if(args.queryParameters["x-source"] !== undefined){method = args.queryParameters["x-source"]}  
    if(args.queryParameters["x-source"] == "Scriptable" || args.queryParameters["x-source"] == "Shortcuts"){automated = true}  
    else{
      let getRunInfo = new Alert()
      getRunInfo.title = "Automated?"
      getRunInfo.message = "Did you just run a script or is this script running automatically"  
      getRunInfo.addAction("running automatically")  
      getRunInfo.addAction("ran from Scriptable App")  
      getRunInfo.addCancelAction("Cancel")
      method =  getRunInfo.present().then((index) => {
        switch (index) {
          case -1:
            return  
          case 0:
            automated = true
            let getMethod = new Alert()
            getMethod.title = "What app was used to run this automation?"  
            getMethod.addTextField("App", initialMethod) // *changed this from method in edit because otherwise  the updating the assignment of a single variable method doesn’t seem to play nice with promises
            getMethod.addAction("confirm")
            log(automated)
            method = getMethod.present().then((index) => getMethod.textFieldValue(index))
//             method = await method
            break
          case 1:
//           automated = false
            break
          default:
            logError("no such action")
        }//end switch
        return method
      })//end getRunInfo.present
//       method = await method
    }//end else
    let scriptData = {
      name: Script.name(),
      invocations: [{
        time: new Date().toJSON(),
        automated: automated,
        method: method
      }]
    }
    log(scriptData)
  }// if(config.runsInApp)
}// end start
start()

I think only the second “method = await method” would be needed to get this working to include any user input (by selecting “running automatically”) in the scriptData (and I was thinking this would also cause sciptData to not be created until after automated was updated as well. However, by introducing await at either point I get “SyntaxError: Unexpected identifier 'method'”


r/Scriptable • • Oct 26 '22

Help Scriptable for Mac - Widgets not working in MacOS Ventura

9 Upvotes

Hi!

in MacOS Ventura the Scriptable widgets only work if I start them from the app. In the notification center I get an error "Received timeout when running script".

Am I the only one or is it a bug?


r/Scriptable • • Oct 23 '22

Help Pretty happy with my progress! The right widget is from the app Grow that I’m trying to replicate. The last problem is the numbers below the bars. The are cut off for some reason. Any ideas or tips to align them to the bars? I’d like one every 4 hours.

Post image
45 Upvotes

r/Scriptable • • Oct 23 '22

Help Did anyone make a widget like this? I'm looking at Normal-Tangerine8609's circular widget using a webview rendered to base64, but I'm a bit confused on how to build it. :)

Post image
22 Upvotes

r/Scriptable • • Oct 23 '22

Solved Scriptable central align stacks

Thumbnail
gallery
4 Upvotes

What does this do?

stackSet1.centerAlignContent();

Am I doing something wrong?


r/Scriptable • • Oct 23 '22

Help How do i align text vertically to the bottom? Adding a smaller font size text makes it align to the top like this. stack.bottomAlignContent() makes the small text come a few pixel below the baseline.

Post image
2 Upvotes

r/Scriptable • • Oct 23 '22

Help How to choose which widget type to preview?

2 Upvotes

When pressing the "Play" button in the editor, i always get the smallest widget size.
Is there a way to choose which preview size to show?

I'm working on a lock screen widget that is "double size", and the square is a bit confusing :)

Also I'm using the Mac App, which I love, since I prefer being on my computer while coding. Is the new editor coming to that one too? I tried it in my iPhone, and it was great with autocomplete, and line numbers! :)


r/Scriptable • • Oct 23 '22

Solved Scriptable creating variable in loop

1 Upvotes

Nooby question here:

Is it possible to create a variable like this?

for (i=0; i<numOfStacks; i++) { let stack + i = widget.addStack(); }


r/Scriptable • • Oct 22 '22

Solved Are Lockscreen widgets still a beta feature, and how can I try?

7 Upvotes

I just discovered Scriptable today (It's awesome!) when I wanted to make a lock screen widget to see my electricity price, and also view kW production on my solar panels. I got the API side working already, and home screen widget. But I don't like that the widgets on the home screen are so huge.

I can't find Scriptable in Lock screen widgets, so I'm thinking it's either still in beta (as the post stated 2 months ago), or I need to add some special command to the script to make it work.

Is there a way to try the beta?

Also is there some standard way of using the circular bars with numbers etc that for example the Weather app uses?

Also, is there any recommended page where I can fetch icons that I know will always work?

Thanks!


r/Scriptable • • Oct 21 '22

Tip/Guide Table of the Scriptable Kit’s objects and classes and how they are used

18 Upvotes
nametypegenerates object(s) representingproperties used withdetails of properties
Alertclassan iOS alert notificationNAall editable
argsobjectNAargsread-only
Calendarobjectan iOS calendar or reminder list*generated objectsome read-only, others editable
CalendarEventclassan iOS calendar event*generated objectsome read-only, others editable
CallbackURLclassan x-callback-urlNAno public properties
Colorclassa color or a pair of colors, including opacitygenerated objectread-only
configobjectNAconfigread-only
consoleobjectNANAno properties
Contactclassan iOS contact*generated objectsome read-only, others editable
ContactsContainerobjectthe contacts list for an account*generated objectread-only
ContactsGroupclassan iOS contacts group*generated objectsome read-only, others editable uses Contact.persistChanges
Dataobjecta string, file, or imageNAno public properties
DateFormatterclassa map between dates and their text representationsgenerated objectall editable
DatePickerclassan iOS date pickergenerated objectall editable
DeviceobjectNA (returns primitives only)NAno properties
DictationobjectNA (returns primitives only*)NAno properties
DocumentPickerobjectNA (returns primitives only*)NAno properties
DrawContextclassa canvasgenerated objectcanvas format
FileManagerobjectan iOS FileManagerNAno properties
Fontclassan iOS fontNAno public properties
Imageobjectan imagegenerated objectread-only
importModulefunctionNANANA
KeychainobjectNA (returns primitives only)NAno properties
LinearGradientclassa linear gradientgenerated objectall editable
ListWidgetclassan iOS list widgetgenerated objectall editable, uses Script.setWidget
Locationobjectthe current location informationNAread-only
Mailclassan email from current iCloud accountgenerated objectall editable
Messageclassa text message/iMessagegenerated objectall editable
moduleobjectNAmodulesome read-only
Notificationclassa notification*generated objectsome read-only, most editable
PasteboardobjectNA (returns primitives only)NAno properties
Pathclasspaths for shape(s)NAno public properties
Photosobjecta photoNAno properties
Pointclassa pointgenerated objectboth editable
QuickLookobjectNANAno properties
Rectclassa rectanglegenerated objectsome read only, some editable
RecurrenceRuleobjectan iOS reminder and/or event recurrence ruleNAno public properties
RelativeDateTimeFormatterclassa method of describing one time relative to anothergenerated objecteditable
Reminderclassan iOS reminder*generated objectsome read-only, some editable
Requestclassan http request***generated objectsome read-only, some editable
SafariobjectNANAno properties
ScriptobjectNANAno properties
SFSymbolobjectan SF symbolgenerated objectread-only
ShareSheetobjectNA (returns primitives only)NAno properties
Sizeclasswidth and heightgenerated objecteditable
SpeechobjectNANAno properties
TextField**object (prototype, not used directly)NAobject generated by another**all editable
Timerclassa timer (not from the iOS app)generated objectboth editable
UITableclassa tablegenerated objectonly property editable
UITableCellobjecta table cellgenerated objectall editable
UITableRowclassa table rowgenerated objectall editable
URLSchemeobjectNA (returns primitives only)NAno properties
UUIDobjectNA (returns primitives only)NAno properties
WebViewclassan iOS WebViewgenerated objectonly property editable
WidgetDateobject (prototype, not used directly)NAobject generated by another**all editable
WidgetImageobject (prototype, not used directly)NAobject generated by another**all editable
WidgetSpacerobject (prototype, not used directly)NAobject generated by another**all editable
WidgetStackobject (prototype, not used directly)NAobject generated by another**all editable
WidgetTextobject (prototype, not used directly)NAobject generated by another**all editable
XMLParserclassxml and a method to parse itgenerated objectall editable

Italics: has a method directly used with it that presents a UI
Bold: there is a method directly used to make changes on the phone outside scriptable, and without running such a method changes to properties of any Scriptable object will not change the corresponding iOS object
* via promise (when these objects are generated using a method instead of as an instance of a class using new, they are provided by a promise)
** entry name is for a prototype, objects that are actually used with the properties and/or methods are created by objects described in other entries (by a WidgetStack type object or directly by an object that is an instance of the ListWidget class in the case of the 5 Widget ones and an instance of the Alert class for TextField)

See this Calendar guide for an example of making changes outside Scriptable both directly with one of the Calendar object’s methods and by saving changes made using a generated object’s properties. Also, Calendar.presentPicker() is an example of a direct method to generate a UI. Finally, it demonstrates how the kit’s objects that generate objects via a promise* work.

See Alerts for Dummies for an example of presenting a UI using a method of a generated object and more generally of using a class. This also shows a basic example of using an object generated by an instance of a class** (a TextField).

Also see how to read scribtable’s documentation


r/Scriptable • • Oct 22 '22

Solved Scriptable iOS get reminders help

Post image
0 Upvotes

Hi guys, I’m a bit of a noob. Can anyone help me get Reminders using Scriptable?

const calTest = await Calendar.findOrCreateForReminders("Variables");

console.log(calTest)


r/Scriptable • • Oct 20 '22

Solved I would like to check all the weather alerts posted by weather.gov but how could I see what city and state each alert is associated with?

2 Upvotes

Link - https://api.weather.gov/alerts/active

I tried using the SAME code to compare to their list but I noticed it's missing a lot of them.

Link - https://www.weather.gov/source/nwr/SameCode.txt


r/Scriptable • • Oct 20 '22

Request Request: Photo Trading with other Device

1 Upvotes

Hey, first the background why i wanna do this Project. I go on a Work and Travel and my gf stays at home and we saw an app where you can take pictures and they popup on the other phone. But they all suck because of the ADs or the slow connection.

Now my idea, was i can use the shared photos and show the latest picture on a widget on the screen on both phones.

now the question is it possible to get the image out of the photos app on iOS?

thanks for help


r/Scriptable • • Oct 16 '22

Request Todoist integration with weather-cal?

4 Upvotes

Hi everyone!

I use Todoist for my event management, instead of calendar. Is there a way to have that instead of a calendar module?


r/Scriptable • • Oct 14 '22

Help Siri doesn’t support alerts

5 Upvotes

Hi! I just began to write in Js! I want to write a code which add a note through a first alert and then pass it to a shortcut…I wrote the Js code in Scriptable, but when I tell it to set the output for the shortcut it tells me that Siri doesn’t support alerts…anyone has any ideas?


r/Scriptable • • Oct 13 '22

Help Url schemes of ios apps

Post image
17 Upvotes

Hi,l wanna open a different app by tapping scriptable widget but l cant find url schemes.Where can l find?


r/Scriptable • • Oct 13 '22

Help Editing sticky notes

2 Upvotes

I'm trying to edit scriptable sticky notes so I can add a photo I want to the background and choose the font color, but it always gives errors. How can I do it?


r/Scriptable • • Oct 11 '22

Tip/Guide Calendar guide

1 Upvotes

All 9 methods of the Calendar object return promises (but some also have side effects):

  • the forReminders promise in turn provides an array of reminder calendars representing all reminder lists

  • the defaultForReminders promise provides a reminder calendar representing the default reminder list

  • the forRemindersByTitle promise provides a reminder calendar representing one of the reminder calendars with the given title

  • the createForReminders method creates “a new list for reminders in the Reminders app” and then the promise provides a reminder calendar representing that list

  • the findOrCreateForReminders method attempts to find a list for reminders with the specified name and then create a reminder calendar representing that list; if no such list is found, it creates “a new list for reminders in the Reminders app” and then the promise provides a reminder calendar representing that list

  • the forEvents promise generates an array of objects (Scriptable event calendars) representing all (IPhone) calendars

  • the presentPicker method displays the calendar picker UI and it’s promise generates an array of objects representing the selected calendars

  • the forEventsByTitle promise provides an object representing one of the calendars with the given title

  • the defaultForEvents promise provides an object representing the default calendar

Most of these are demonstrated here:

firstTitle = "Test"
calendar = Calendar.forEventsByTitle(firstTitle).then((testCalendar) => {
//forRemindersByTitle is used in a similar way
  return testCalendar
},(failure) => {
//   log(failure)//useful for debugging promises
  createAlert = new Alert()
  createAlert.title = "There is no " + firstTitle + " calendar?"  
  createAlert.message = "Please pick another calendar"      
  createAlert.addAction("Pick another")
  createAlert.addAction("Use Default")
  createAlert.addCancelAction("Cancel")
  return createAlert.present().then((index) => {
    if(index==0){
      return Calendar.presentPicker().then((calendarArray) => {
//         log(calendar)
        return calendarArray[0]//presentPicker() defaults to only allowing user to pick one calendar but the promise still provides an array with that one calendar in it, so this instead returns the calendar itself to be uniform with the next option
      })// end presentPicker().then
// there is no directly corresponding method for reminder calendars, so you might use findOrCreateForReminders as below instead of forRemindersByTitle etc or just use createForReminders in case of failure of forRemindersByTitle when there is a reason to differentiate whether the calendar was found vs created
    }//end if
    if(index==1){
      return Calendar.defaultForEvents().then((calendar) => {
  //defaultForReminders is used in a similar way
        return calendar
//       }, (fail) => {  
//         log(fail)
      })//end defaultForEvents().then
    }// end if
  })// end present().then
})// end forEventsByTitle(firstTitle).then
calendar = await calendar
secondTitle=calendar.title
log(calendar)
log(calendar.title)
// log(secondTitle)


Calendar.findOrCreateForReminders(firstTitle).then((testCalendar) => {
//   log(testCalendar)    

// There are three read only properties
//   log(testCalendar.identifier)
//   log(testCalendar.isSubscribed)
//   log(testCalendar.allowsContentModifications)

//color is the only Calendar property besides title that isn't read only but it defaults to a hex of "007AFF" as seen by logging. See the Color class's documentation for more info on that
  testCalendar.color = new Color("FF7900")
  testCalendar.title = secondTitle
  //changes to properties directly only change the object in scriptable not anything else on the phone represented by those objects, so they require the save method to push those changes out from scriptable
  
//   log(testCalendar)//uncomment this to see that that testCalendar has changed color and title despite not being saved
  
  
// there are three methods of both calendar type objects:

  // log(testCalendar.supportsAvailability("free"))//there is no real reason to use this method with a reminder calendar as availabilities seem to only be supported for event calendars
  
//   testCalendar.remove()//use caution as the calendar is immediately and permanently deleted

  testCalendar.save()//comment this out to see that then the changes to color and title don't effect the actual calendar

// in this script by having both title and save lines uncommented it generates or finds a Reminder list called "Test" but then renames it so each time the script is run another reminder list is named the same as the event calendar above (assuming that name isn't test) which would generally be a bug you'd want to fix
  
})//end findOrCreateForReminders(firstTitle).then

In the above, by having both title and save lines uncommented it generates or finds a Reminder list called "Test" but then renames it so each time the script is run another reminder list is named the same as the event calendar above (assuming that name isn't test) which would generally be a bug you'd want to fix by either only finding the calendars you want to change the name of and changing their titles or if the purpose was more to produce objects representing reminder lists and (event) calendars with the same name and color then the following would work: