Local Commands
Commands that run scripts on your computer.
Last updated
Commands that run scripts on your computer.
Last updated
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.
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.
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
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.
Slapdash runs JavaScript commands using Node.
Here is an example of a JavaScript command that displays a list with two options:
When you run the command in the Command Bar, Slapdash will execute the underlying script:
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.
When you run the command in the Command Bar, Slapdash will execute the underlying script:
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:
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
:
You can use Python v2 too: just change the shebang line to #!python2
as usual.
macOS should have Ruby pre-installed (or you can install it with brew install ruby
). Put the following to e.g. command.rb
:
Perl is conveniently pre-installed on macOS. If you still remember how to write in Perl put the following to command.pl
:
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
:
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.
When searching for a programming language binary to execute the command script, we use the following approach:
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 look for the installed Ruby binary.
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
.
Finally, Slapdash will use the OS's PATH
environment variable to resolve the binary.