Your custom code and commands
Lodash
We have lodash defined as _
global.
Home folder structure
In order of being evaluated:
~/voicecode/ <- working directory
~/voicecode/packages/ <- packages you have downloaded
~/voicecode/settings.coffee <- main settings file, license goes here
~/voicecode/**/*.coffee <- your code (commands and/or more settings)
~/voicecode/**/*.js <- your code (commands and/or more settings)
~/voicecode/misc/* <- ignored by the above 2 rules
Dragon vocabulary files
VoiceCode auto generates some special files for importing into Dragon in order to increase recognition accuracy. They are located in ~/voicecode/generated/*.xml
. These files our regenerated every time you enable/disable commands or edit settings that affect the grammar. After getting most of your commands set up you should import these files. You should also make a habit of importing them again from time to time as they greatly improve recognition accuracy. Depending on how much you are changing the grammar, importing once every several weeks is a good default.
User command files
For every user-file (.coffee or .js) you create, we create a package named user:filename
.
From inside that file, you can reference the current file's package as the variable simply named Package
.
// Package closure around filename.coffee
console.log(Package)
Package.command('my-test-command', {
spoken: 'does it work',
enabled: true,
action: function() {
this.string 'yes it works!'
}
}
The above will create a command with id user:filename:my-test-command
which can be triggered by saying does it work
and is enabled by default.
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 other packages' command
Let's say you have an application Notepad.app, for which you want to implement the delete:lines
🔉snipline🔉 command. First you need to find the bundle id for Notepad.app. Either $ osascript -e 'id of app "Notepad"'
or click on the bug icon on VoiceCode Log and look for currentApplicationChanged
event which fires when Notepad.app gains focus.
There are two slightly different ways you could do this:
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"
Scope.register({
name: 'notepad',
application: 'com.microsoft.Notepad.app' // bundle.Id
})
Next use this file's Package
to create implement commands, giving at the scope name for which the implementations apply:
Package.implement({
scope: 'notepad'
}, {
'delete:lines': function(){
// implementation
},
'other-package:other-command': function(){
// another implementation
}
})
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.
notepad = Packages.register({
name: 'notepad'
application: 'com.microsoft.Notepad.app' // bundle.Id, scope will be auto generated
})
A scope is automatically generated for this package since it has an application
parameter. Next, use this package to create some commands. These commands will automatically only be active when the package is active:
notepad.implement({
'delete:lines': function(){
// implementation
},
'other-package:other-command': function(){
// another implementation
}
})
pro tip
Use core:insert-command-id
🔉sherlock🔉 command followed by the command you want to get the id for:
🔉sherlock snipline🔉 => types `delete:lines`
🔉sherlock sherlock🔉 => types `core:insert-command-id`
🔉sherlock shock🔉 => types `common:enter`
This is especially useful when adding to Settings.vocabulary.sequences