https://github.com/haykam821/shortcuts.js
A simple library for Apple's Shortcuts.
https://github.com/haykam821/shortcuts.js
api shortcuts
Last synced: 11 months ago
JSON representation
A simple library for Apple's Shortcuts.
- Host: GitHub
- URL: https://github.com/haykam821/shortcuts.js
- Owner: haykam821
- License: mit
- Created: 2018-09-21T18:29:54.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-01-20T18:22:21.000Z (over 6 years ago)
- Last Synced: 2024-11-19T17:15:45.304Z (over 1 year ago)
- Topics: api, shortcuts
- Language: JavaScript
- Size: 662 KB
- Stars: 23
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Shortcuts.js
[](https://github.com/haykam821/Shortcuts.js/releases/latest)
[](https://www.npmjs.com/package/shortcuts.js)
[](https://travis-ci.com/haykam821/Shortcuts.js)
A simple library for Apple's Shortcuts.
## Installation
You can install this module with NPM or [Yarn](https://yarnpkg.com/):
```shell
npm install shortcuts.js
yarn add shortcuts.js
```
## Usage
First, you must require the library:
```js
const shortcuts = require("shortcuts.js");
```
Afterwards, you can use its methods. One of the simplest things you can do with this library is grab the ID from an iCloud URL. This is useful for more complex methods such as getting a shortcut's details from a user-submitted value, which might not always be just the ID.
```js
// Get an ID from a iCloud URL
const id = shortcuts.idFromURL("https://www.icloud.com/shortcuts/903110dea9a944f48fef9e94317fb686");
```
In addition, Shortcuts.js can retrieve metadata from the shortcut itself in addition to the overview information. This example uses promise chaining to get shortcut metadata from an iCloud URL:
```js
// Chain promises to get a shortcut's metadata
shortcuts.getShortcutDetails(id).then(shortcut => {
console.log(`Hi, I'm ${id}! What's your name?`);
return shortcut.getMetadata();
}).then(metadata => {
console.log(`I have ${metadata.actions.length} actions! How cool is that?`);
}).catch(error => {
console.log(`${error.code}? How could this happen!`);
});
```
The following example uses [async/await](https://javascript.info/async-await) to achieve the same purpose:
```js
async function getBasicInfo() {
const shortcut = await shortcuts.getShortcutDetails(id);
const metadata = await shortcut.getMetadata();
return `Hi! I'm ${shortcut.name}. I have ${metadata.importQuestions.length} import questions, and I'm happy to be here. What's your name?`;
}
getBasicInfo().then(console.log).catch(error => {
console.log(`There was an error: ${error.code}. At least I can say that I tried...`);
});
```
## Documentation
Documentation is available on [GitHub Pages](https://haykam821.github.io/Shortcuts.js/).
## See also
* [Shortcutify](https://github.com/haykam821/Shortcutify), the framework for building shortcuts with JavaScript.