Scriptable

vaughan.halearrow-up-right June 17, 2020, 8:21am

Suggested Approach?

I am trying to create a shortcut/script/automation that:

  • calls and API

  • displays the results in a similar way to a tableview (which has a couple action buttons on each row)

  • when a button is selected continues on with the shortcut (or runs a different shortcut) passing the selected rows details. Has anyone done anything similar or got any suggestions.

schl3ckarrow-up-right June 17, 2020, 10:33am

Hi!

let btn = new UITableCell.button("caption")
row.addCell(btn)

and then assign your callback function to btn.onTaparrow-up-right.

In the callback function you can do whatever you like. If you want to run a shortcut use

Safari.open("shortcuts://run-shortcut?name=" + encodeURIComponent("your shortcut name here") + "&input=" + "your data here in your favourite string format (base64, json, URL encoded,...)")

(If you want to transfer the word “clipboard” to shortcuts, you have to write "&input=text&text=" instead of "&input=". It seems that this isn’t documented anywhere, but it was like that 2 years ago. If you don’t do it like that, shortcuts will use the contents of the clipboard as input)

An example table:

I can’t give you more advice because that depends on your specific case.

vaughan.halearrow-up-right June 17, 2020, 11:06am

Thank you so much for your detailed reply. I will take this a have a good at applying it all tomorrow. Can you tell me if you can do much styling to rows and cells etc?

schl3ckarrow-up-right June 17, 2020, 10:28pm #4

According to the docs the only styling available is

  • separators between rows ( UITable.showSeparators)

  • regular or bold font ( UITableRow.isHeader)

  • background color of each row

  • height of each row

  • space between the cells in one row ( UITableRow.cellSpacing)

  • relative width of cells (to each other in the same row: UITableCell.widthWeight)

  • color of text (not buttons)

  • alignment of cells

If you for example want a separator between multiple rows to create something like sections without showing separators between every row, you can set the background color of a row to black and it’s height to something small (like 2 or 3, just experiment with it).

If you need more styling options, then you can make the table in HTML with custom CSS and display that in a WebView.

Powered by Discoursearrow-up-right, best viewed with JavaScript enabled

Last updated