Local Commands
Commands that are scripts that run 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 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 Mac OS. Just create a my-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 via NodeJS.
1
const response = {
2
view: {
3
type: "list",
4
options: [
5
{
6
title: "Open Slapdash",
7
action: {
8
type: "open-url",
9
url: "https://slapdash.com"
10
}
11
},
12
{
13
title: "Copy Heart Emoji",
14
action: {
15
type: "copy",
16
value: "❤️"
17
}
18
}
19
]
20
}
21
};
22
23
console.log(JSON.stringify(response));
Copied!

TypeScript

Slapdash runs TypeScript commands via NodeJS and ts-node TypeScript utility.
If you are developing your command inside a package, Slapdash will also look inside node_modules for the ts-node executable.
1
const response = {
2
view: {
3
type: "list",
4
options: [
5
{
6
title: "Open Slapdash",
7
action: {
8
type: "open-url",
9
url: "https://slapdash.com",
10
},
11
},
12
{
13
title: "Copy Heart Emoji",
14
action: {
15
type: "copy",
16
value: "❤️",
17
},
18
},
19
],
20
},
21
};
22
23
console.log(JSON.stringify(response));
Copied!

Bash

You already have bash (or zsh) on your Mac. No need to install anything. Just create e.g. my-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. my-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. my-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 my-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. my-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:
First, 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.
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 try to find the installed Ruby to run the command.
When resolving relative binary paths, Slapdash will check the current directory's node_modules/.bin folder. This is a bit of sugar for the JavaScript ecosystem, letting Slapdash find tools like ts-node that could be installed locally to the javascript package of the command.
Finally, Slapdash will use the OS's PATH environment variable to resolve the binary.
Last modified 6d ago