Getting Started
/

Custom Code

Lodash

We have the highly useful lodash library defined as `_` globally.

Home folder structure

In order of being evaluated:

  1. `~/voicecode/`: working directory
  2. `~/voicecode/packages/`: packages you have downloaded
  3. `~/voicecode/settings.coffee`: main settings file, license goes here
  4. `~/voicecode/**/*.coffee`: your code (commands and/or more settings)
  5. `~/voicecode/**/*.js`: your code (commands and/or more settings)
  6. `~/voicecode/misc/*`: ignored by the above rules

User command files

For every new file (.coffee or .js) you create, we create a package named `user:filename`. From inside that file, you can reference the current file's auto-generated package as the variable simply named `Package`.

unboundmusic/dc2158ff83dc85dbf9babc60beca7a11

The above will create a command with id `user:my-file:my-test-command` which can be triggered by saying @does it [email protected]

The `Package` variable is a convenient shortcut, but you don't have to use it if you want to just create your own package with its own name.

Implementing commands from other packages

Let's say you have an application Notepad.app, for which you want to implement the `delete:lines` @[email protected] command. First you need to find the bundle id for Notepad.app. Either run the following command at a shell prompt:

```

$ osascript -e 'id of app "Notepad"'

``

OR

  • click on the debug icon in the VoiceCode Log window
  • look for the `currentApplicationChanged` event which will fire when Notepad.app gains focus.

There are two slightly different ways you could implement the `delete:lines` command:

1. Using the `Package` already generated for the current user file

First you would create a scope that encapsulates when this group of commands should be "active"

unboundmusic/0d9741da6cbd5a63b1c3ffdc17c00e3d

Next use this file's Package to create or implement commands, supplying the scope name for which the implementations apply:

unboundmusic/b7e346f3df107573ea8a69619cce2e95

2. Generating a new package from scratch

First, create a package, give it a good name, and set the applications and/or conditions for when this package should be "active".

unboundmusic/b22afb987dafe8851e94d1aaa6cf2254

A scope is automatically generated for this package since it has an `application` parameter (the package `name` will be used as the `name` of the auto generated Scope). Next, use this package to implement some commands that were already created somewhere else. These implementations will automatically be active only when the package is active:

unboundmusic/e5246d304ce1d87b2c115861b1cd3690

pro tip

Use `core:insert-command-id` @[email protected] command followed by the command you want to get the id for:

@sherlock [email protected] => will type `delete:lines`

@sherlock [email protected] => will type `core:insert-command-id`

@sherlock [email protected] => will type `common:enter`

This is especially useful when adding to `Settings.vocabulary.sequences`