lacona-command-osx
Version:
Lacona Extensions for OSX, tied into the global-context hosted API
46 lines (38 loc) • 977 B
JavaScript
import {Source} from 'lacona-phrase'
export default class Applescript extends Source {
onCreate () {
this.triggered = false
this.replaceData([])
if (this.props.fetchOn === 'create') { this.fetch() }
}
onActivate () {
if (this.props.fetchOn === 'activate') { this.fetch() }
}
onDeactivate () {
if (this.props.fetchOn === 'activate') { this.replaceData([]) }
if (this.props.fetchOn === 'triggerOnce') {
this.triggered = false
}
}
trigger () {
if (this.props.fetchOn === 'triggerOnce' && !this.triggered) {
this.fetch()
this.triggered = true
} else if (this.props.fetchOn === 'trigger') {
this.fetch()
}
}
fetch () {
global.applescript(this.props.code, this.props.keys, (err, data) => {
if (err) {
console.log('Applescript Error:')
console.log(err)
return
}
this.replaceData(data)
})
}
}
Applescript.defaultProps = {
fetchOn: 'create'
}