Local Commands
Commands that run scripts on your computer.
Local commands are just scripts that run on your computer. Slapdash knows how to run scripts in the most popular languages.
Even if Slapdash doesn't support your language out of the box, you can just use shebang syntax, or create a bash wrapper to call into your program.

Create Local Command

To create a local command, run Create New Command in the Command Bar, choose Local Script as a type, select the script file on your computer, give your command a name and press Create Command.

Language Support

We try to support as many languages as possible. Below you'll find a list of languages you can use to build Slapdash commands.
In practice, you can use a shebang directive to point to an interpreter of your choice.
  • AppleScript
  • bash / zsh
  • JavaScript
  • Perl
  • PowerShell
  • Python
  • Ruby
  • PHP
  • TypeScript

AppleScript

Support for AppleScript is baked into macOS. Just create a command.applescript file anywhere and start experimenting!
Here's an example of an AppleScript command which toggles the Mac OS system dark mode.
1
#!/usr/bin/osascript
2
3
tell application "System Events"
4
tell appearance preferences
5
set dark mode to not dark mode
6
end tell
7
end tell
Copied!

JavaScript

Slapdash runs JavaScript commands using Node.
Here is an example of a JavaScript command that displays a list with two options:
1
// command.js
2
3
const response = {
4
view: {
5
type: "list",
6
options: [
7
{
8
title: "Open Slapdash",
9
action: {
10
type: "open-url",
11
url: "https://slapdash.com"
12
}
13
},
14
{
15
title: "Copy Heart Emoji",
16
action: {
17
type: "copy",
18
value: "❤️"
19
}
20
}
21
]
22
}
23
};
24
25
console.log(JSON.stringify(response));
Copied!
When you run the command in the Command Bar, Slapdash will execute the underlying script:
1
node command.js
Copied!

TypeScript

Slapdash runs TypeScript commands using NodeJS and ts-node.
If you are building a command inside some package, Slapdash will also look inside its node_modules for the ts-node executable. If it can't find ts-node there it will look for ts-node in the global node modules location on your computer.
1
// command.ts
2
3
// Optionally, import our npm package to get TS types for Command Response.
4
import { CommandResponse } from "@slapdash/command-response-types";
5
6
const response: CommandResponse = {
7
view: {
8
type: "list",
9
options: [
10
{
11
title: "Open Slapdash",
12
action: {
13
type: "open-url",
14
url: "https://slapdash.com",
15
},
16
},
17
{
18
title: "Copy Heart Emoji",
19
action: {
20
type: "copy",
21
value: "❤️",
22
},
23
},
24
],
25
},
26
};
27
28
console.log(JSON.stringify(response));
Copied!
When you run the command in the Command Bar, Slapdash will execute the underlying script:
1
ts-node command.ts
Copied!

Bash

You already have bash (or zsh) on your Mac. No need to install anything. Just create e.g. command.sh file anywhere and start bashing:
1
#!/bin/bash
2
3
echo '{
4
"view": {
5
"type": "list",
6
"options": [
7
{
8
"title": "Open Slapdash",
9
"action": {
10
"type": "open-url",
11
"url": "https://slapdash.com"
12
}
13
},
14
{
15
"title": "Copy Heart Emoji",
16
"action": {
17
"type": "copy",
18
"value": "❤️"
19
}
20
}
21
]
22
}
23
}'
Copied!

Python

macOS has both Python v2 and Python v3 pre-installed, so you can just use it by default. Put the following to e.g. command.py:
1
#!python3
2
# -*- coding: utf-8 -*-
3
import json
4
5
print(json.dumps({
6
"view": {
7
"type": "list",
8
"options": [
9
{
10
"title": "Open Slapdash",
11
"action": {
12
"type": "open-url",
13
"url": "https://slapdash.com"
14
}
15
},
16
{
17
"title": "Copy Heart Emoji",
18
"action": {
19
"type": "copy",
20
"value": "❤️"
21
}
22
}
23
]
24
}
25
}))
Copied!
You can use Python v2 too: just change the shebang line to #!python2 as usual.

Ruby

macOS should have Ruby pre-installed (or you can install it with brew install ruby). Put the following to e.g. command.rb:
1
#!/usr/bin/env ruby
2
require 'json'
3
4
print JSON.generate({
5
"view": {
6
"type": "list",
7
"options": [
8
{
9
"title": "Open Slapdash",
10
"action": {
11
"type": "open-url",
12
"url": "https://slapdash.com"
13
}
14
},
15
{
16
"title": "Copy Heart Emoji",
17
"action": {
18
"type": "copy",
19
"value": "❤️"
20
}
21
}
22
]
23
}
24
})
Copied!

Perl

Perl is conveniently pre-installed on macOS. If you still remember how to write in Perl put the following to command.pl:
1
#!/usr/bin/perl -w
2
use utf8;
3
use JSON;
4
5
print encode_json({
6
"view" => {
7
"type" => "list",
8
"options" => [
9
{
10
"title" => "Open Slapdash",
11
"action" => {
12
"type" => "open-url",
13
"url" => "https://slapdash.com"
14
}
15
},
16
{
17
"title" => "Copy Heart Emoji",
18
"action" => {
19
"type" => "copy",
20
"value" => "❤️"
21
}
22
}
23
]
24
}
25
})
Copied!

PHP

Some version of PHP is pre-installed on macOS, so it should work out of the box. Put the following to e.g. command.php:
1
#!php
2
<?php
3
echo json_encode([
4
"view" => [
5
"type" => "list",
6
"options" => [
7
[
8
"title" => "Open Slapdash",
9
"action" => [
10
"type" => "open-url",
11
"url" => "https://slapdash.com"
12
]
13
],
14
[
15
"title" => "Copy Heart Emoji",
16
"action" => [
17
"type" => "paste",
18
"value" => "❤️"
19
]
20
]
21
]
22
]
23
]);
Copied!

PowerShell

PowerShell is already pre-installed on Windows. Just create a file with a .ps1 extension. Here's an example that will empty your recycling bin.
1
Clear-RecycleBin -Force
Copied!

Locating Language Binaries

When searching for a programming language binary to execute the command script, we use the following approach:
  1. 1.
    We check the first line of the script, the same way it's done in Unix-like systems by looking for the shebang directive. If the first line looks like #!/path/to/binary or just #!binary, Slapdash calls the referenced interpreter to execute the command.
  2. 2.
    If there is no shebang directive, Slapdash will try to infer the language binary from the file's extension. For example, if it's a *.rb file, Slapdash will look for the installed Ruby binary.
  3. 3.
    If the script is within an npm package (JavaScript/TypeScript), Slapdash will check the current directory's node_modules/.bin folder to look for tools like ts-node.
  4. 4.
    Finally, Slapdash will use the OS's PATH environment variable to resolve the binary.
Last modified 7d ago