QuickLook issue


#1

When I run the sample script in 'Welcome to Scriptable" (gets MacStories headlines) as a Siri shortcut, the table appears briefly in the QuickLook window but then disappears. Is this standard behavior for QuickLook? Is it possible to set a duration to ensure the output remains onscreen? Not seeing any other documentation around controlling QuickLook. Wondering if such controls exist.


#2

Hi,

That is certainly not expected. It sounds like a bug and it seems that I can reproduce it. I’ll look into it for the next update.

Thanks for reporting this. I appreciate the feedback.


#3

I’ve looked into the issue and unfortunately it seem that the script is using too much memory (RAM). iOS puts a very hard limit on how much memory an app can use when running in Siri and when it’s exceeded, the app is killed.

Loading the images causes a very high memory peak so in order to address this on a script level, we can opt to not show the images or limit the number of stories shown when the script is run with Siri. I’ve modified the script to adopt the latter. Here’s the updated script.

// Shows latest news from MacStories in a table.
// The table shows an image from the article, if available, and the title of the article.
let url = "https://macstories.net/feed/json"
let req = new Request(url)
let json = await req.loadJSON()
let allItems = json.items
// We only show a subset of the items when running with Siri
if (config.runsWithSiri) {
  items = json.items.slice(0, 5)
} else {
  items = json.items
}
let table = new UITable()
for (item of items) {
  let row = new UITableRow()
  let imageURL = extractImageURL(item)
  let title = decode(item.title)
  let imageCell = row.addImageAtURL(imageURL)
  let titleCell = row.addText(title)
  imageCell.widthWeight = 20
  titleCell.widthWeight = 80
  row.height = 60
  row.cellSpacing = 10
  table.addRow(row)
}
QuickLook.present(table)

function extractImageURL(item) {
  let regex = /<img src="(.*)" alt="/
  let html = item["content_html"]
  let matches = html.match(regex)
  if (matches && matches.length >= 2) {
    return matches[1]
  } else {
    return null
  }
}

function decode(str) {
  let regex = /&#(\d+);/g
  return str.replace(regex, (match, dec) => {
    return String.fromCharCode(dec)
  })
}