Created
September 21, 2019 11:37
-
-
Save simonbs/a2b76112b44da639b4e6519079b3b386 to your computer and use it in GitHub Desktop.
Reads a text file containing iCloud links to shortcuts and imports the shortcuts into the Shortcuts app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: pink; icon-glyph: file-import; | |
let fm = FileManager.iCloud() | |
let bookmarkName = "Shortcut Links" | |
let filePath = fm.bookmarkedPath(bookmarkName) | |
let contents = fm.readString(filePath) | |
let links = contents.split("\n") | |
importLinks(links) | |
function importLinks(links) { | |
if (links.length == 0) { | |
return | |
} | |
let link = links[0] | |
let tail = links.slice(1) | |
let pathComps = link.split("/") | |
let pathCompIdx = pathComps.length - 1 | |
let uuid = pathComps[pathCompIdx] | |
let baseURL = "workflow://shortcuts/" | |
+ encodeURIComponent(uuid) | |
let url = new CallbackURL(baseURL) | |
url.addParameter("url", link) | |
url.open().then(() => { | |
importLinks(links) | |
}).catch(err => { | |
// An error is okay because Shortcuts doesn't return to third part apps when importing so the operation will be cancelled. | |
importLinks(tail) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment