{"id":13462469,"url":"https://github.com/joshfarrant/shortcuts-js","last_synced_at":"2025-03-25T01:32:15.244Z","repository":{"id":33370695,"uuid":"156233144","full_name":"joshfarrant/shortcuts-js","owner":"joshfarrant","description":"A JavaScript iOS 12 Shortcuts creator","archived":true,"fork":false,"pushed_at":"2023-06-29T15:36:41.000Z","size":8228,"stargazers_count":1693,"open_issues_count":58,"forks_count":101,"subscribers_count":39,"default_branch":"master","last_synced_at":"2024-10-29T11:11:26.044Z","etag":null,"topics":["apple","automation","ios","ios12","javascript","nodejs","shortcuts","typescript"],"latest_commit_sha":null,"homepage":"https://shortcuts.fun","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joshfarrant.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-11-05T14:43:55.000Z","updated_at":"2024-10-22T08:31:09.000Z","dependencies_parsed_at":"2024-04-20T07:44:49.074Z","dependency_job_id":null,"html_url":"https://github.com/joshfarrant/shortcuts-js","commit_stats":{"total_commits":608,"total_committers":23,"mean_commits":"26.434782608695652","dds":0.6447368421052632,"last_synced_commit":"ef3c54b05819121043cabdf2d5c97486a48f2557"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshfarrant%2Fshortcuts-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshfarrant%2Fshortcuts-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshfarrant%2Fshortcuts-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshfarrant%2Fshortcuts-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joshfarrant","download_url":"https://codeload.github.com/joshfarrant/shortcuts-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245382177,"owners_count":20606165,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apple","automation","ios","ios12","javascript","nodejs","shortcuts","typescript"],"created_at":"2024-07-31T12:00:48.761Z","updated_at":"2025-03-25T01:32:14.545Z","avatar_url":"https://github.com/joshfarrant.png","language":"TypeScript","funding_links":[],"categories":["Uncategorized","TypeScript"],"sub_categories":["Uncategorized"],"readme":"![Shortcuts JS Logo](./assets/logo.png)\n\n[![GitHub license](https://img.shields.io/badge/license-GPL-blue.svg)](https://github.com/joshfarrant/shortcuts-js/blob/master/LICENSE)\n[![npm version](https://img.shields.io/npm/v/@joshfarrant/shortcuts-js.svg?colorB=blue)](https://www.npmjs.com/package/@joshfarrant/shortcuts-js)\n[![Build Status](https://img.shields.io/travis/joshfarrant/shortcuts-js/master.svg)](https://travis-ci.org/joshfarrant/shortcuts-js)\n[![Coverage Status](https://coveralls.io/repos/github/joshfarrant/shortcuts-js/badge.svg?branch=master)](https://coveralls.io/github/joshfarrant/shortcuts-js?branch=master)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg)](https://github.com/joshfarrant/shortcuts-js/blob/master/.github/CONTRIBUTING.md)\n[![Discord](https://img.shields.io/discord/537267258922237954.svg?label=Discord\u0026logo=discord\u0026style=flat)](https://discord.gg/pyvcYbB)\n\nA Node.js iOS 12 Shortcuts creator.\n\nFind out more at [Shortcuts.fun](https://shortcuts.fun).\n\n[@joshfarrant/shortcuts-js](https://www.npmjs.com/package/@joshfarrant/shortcuts-js) on npm.\n\n[NPM](https://www.npmjs.com/package/@joshfarrant/shortcuts-js) | [Documentation](https://docs.shortcuts.fun/globals.html) | [Contributing](https://github.com/joshfarrant/shortcuts-js/blob/master/.github/CONTRIBUTING.md) | [Medium](https://medium.com/@JoshFarrant/creating-ios-12-shortcuts-with-javascript-and-shortcuts-js-942420ca9904) | [Discord](https://discord.gg/pyvcYbB)\n\nSee [this issue](https://github.com/joshfarrant/shortcuts-js/issues/6) for a complete list of all Actions implemented so far.\n\nWe have a Discord! If you need any help or have any questions, come and say hi! [Join the Discord](https://discord.gg/pyvcYbB)\n\n#### Is the Action you want not available?\n\nWe're still working our way through the long list of built-in Shortcut Actions, if there's one you need sooner rather than later then [Open an Issue](https://github.com/joshfarrant/shortcuts-js/issues/new/choose) and let us know; we might be able to prioritise it.\n\nAlternatively, it's super easy to add an Action yourself! A simple Action should only take about 15 minutes to implement. Check out the [Contributing Guide](https://github.com/joshfarrant/shortcuts-js/blob/master/.github/CONTRIBUTING.md) for more info on where to start. If for any reason you get stuck just [Open an Issue](https://github.com/joshfarrant/shortcuts-js/issues/new/choose). We're happy to help!\n\n## Minimal Example\n\n```sh\nnpm install @joshfarrant/shortcuts-js\n```\n\n```js\n// Only used to create the .shortcut file\nconst fs = require('fs');\n\nconst {\n  actionOutput,\n  buildShortcut,\n  withVariables,\n} = require('@joshfarrant/shortcuts-js');\nconst {\n  calculate,\n  comment,\n  number,\n  showResult\n} = require('@joshfarrant/shortcuts-js/actions');\n\n// We'll use this later to reference the output of a calculation\nconst calcVar = actionOutput();\n\n// Define our list of actions\nconst actions = [\n  comment({\n    text: 'Hello, world!',\n  }),\n  number({\n    number: 42,\n  }),\n  calculate({\n    operand: 3,\n    operation: '/',\n  }, calcVar),\n  showResult({\n    /**\n     * We can use the result of the calculation in this Shortcuts's input\n     * by passing the string to the 'withVariables' tag function\n     */\n    text: withVariables`Total is ${calcVar}!`,\n  }),\n];\n\n// Generate the Shortcut data\nconst shortcut = buildShortcut(actions);\n\n// Write the Shortcut to a file in the current directory\nfs.writeFile('My Fancy Shortcut.shortcut', shortcut, (err) =\u003e {\n  if (err) {\n    console.error('Something went wrong :(', err);\n    return;\n  }\n  console.log('Shortcut created!');\n});\n```\n\nRunning this code will build a Shortcut named '_My Fancy Shortcut.shortcut_' in the current directory.\n\nThis can be AirDropped to an iPhone or iPad running iOS 12, at which point it will be automatically opened and imported into Shortcuts.\n\n![Shortcut Image](./assets/demo-shortcut.jpeg)\n\n## Further Examples\n\nFor brevity, these examples omit the code for writing the file to disk and just focus on building the Shortcut. See the [Minimal Example](#Minimal-Example) above for an example of how to create the .shortcut file.\n\n\n### Battery level checker, with conditional action\n\n```js\nconst {\n  actionOutput,\n  buildShortcut,\n  withVariables,\n} = require('@joshfarrant/shortcuts-js');\nconst {\n  conditional,\n  getBatteryLevel,\n  setLowPowerMode,\n  showResult,\n} = require('@joshfarrant/shortcuts-js/actions');\n\nconst batteryLevel = actionOutput();\n\nconst actions = [\n  getBatteryLevel({}, batteryLevel),\n  conditional({\n    input: '\u003c',\n    value: 20,\n    ifTrue: [\n      setLowPowerMode({\n        value: true,\n      }),\n      showResult({\n        text: withVariables`Your battery is at ${batteryLevel}%, you might want to charge it.`,\n      }),\n    ],\n    ifFalse: [\n      showResult({\n        text: withVariables`Your battery is at ${batteryLevel}%, you're probably fine for now.`,\n      }),\n    ],\n  })\n];\n\nconst shortcut = buildShortcut(actions);\n```\n\n![Battery Checker Shortcut Image](./assets/battery-checker-shortcut.jpeg)\n\n### Shortcut folder creator\n\nThis example creates folders and subfolders of Shortcuts so they can be easily run from one 'Folder' Shortcut.\n\nThis Shortcut could be tedious to set up using the drag-and-drop interface of the Shortcuts app, however we can simplify the generation of this Shortcut by using a function to build our actions from a predefined array of strings.\n\n```js\nconst {\n  buildShortcut,\n  withVariables,\n} = require('@joshfarrant/shortcuts-js');\nconst {\n  conditional,\n  getBatteryLevel,\n  setLowPowerMode,\n  showResult,\n} = require('@joshfarrant/shortcuts-js/actions');\n\nconst foldersArr = [\n  ['Health', [ // The name of the folder\n    'Log Sleep', // The names of Shortcuts to contain in that folder\n    'Log Run',\n    'Log Cycle',\n  ]],\n  ['Home', [\n    ['Lights', [\n      'Lights On', // We can go as many levels deep as we like\n      'Lights Off',\n    ]],\n    ['Heating', [\n      'Heating On',\n      'Heating Off',\n    ]],\n    ['Cameras', [\n      'Cameras On',\n      'Cameras Off',\n    ]],\n    ['Door', [\n      'Lock Door',\n      'Unlock Door',\n    ]],\n  ]],\n  ['Audio', [\n    'Play Playlist',\n    'Resume Podcast'\n  ]],\n];\n\nconst buildFolders = (arr) =\u003e (\n  arr.map(shortcut =\u003e (\n    Array.isArray(shortcut) ? ({\n      label: shortcut[0],\n      actions: [\n        chooseFromMenu({\n          prompt: shortcut[0],\n          items: buildFolders(shortcut[1]),\n        }),\n      ],\n    }\n    ) : ({\n      label: shortcut,\n      actions: [\n        runShortcut({\n          name: shortcut,\n        }),\n      ],\n    })\n  ))\n);\n\nconst actions = [\n  chooseFromMenu({\n    prompt: 'Open',\n    items: buildFolders(foldersArr),\n  }),\n];\n\nconst shortcut = buildShortcut(actions);\n```\n\n![Folder Shortcut Gif](https://thumbs.gfycat.com/TangibleRemorsefulAmericancrayfish-small.gif)\n\n## Anything Else\n\nIf you're having any issues getting started, or you'd just like some advice, then please don't be afraid to [Open an Issue](https://github.com/joshfarrant/shortcuts-js/issues/new/choose), we're here to help!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshfarrant%2Fshortcuts-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoshfarrant%2Fshortcuts-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshfarrant%2Fshortcuts-js/lists"}