dansays / homebridge-applescript

Applescript plugin for homebridge: https://github.com/nfarina/homebridge
20 stars 8 forks source link

Unhandled Error Detected : Error: spawn osascript ENOENT #8

Closed JangoBritt closed 7 years ago

JangoBritt commented 7 years ago

I'm using the AppleScript-file fork of this plugin, but there's no issues forum there.

When switching on, or increasing the brightness on this script, I get a fatal error in the homebridge log

16:56:43 - Unhandled Error Detected : Error: spawn osascript ENOENT at exports._errnoException (util.js:870:11) at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32) at onErrorNT (internal/child_process.js:344:16) at nextTickCallbackWith2Args (node.js:442:9) at Immediate._tickCallback as _onImmediate at processImmediate as _immediateCallback

My config.json is:

{ "accessory": "ApplescriptFile", "name": "Thomas Lullabies", "on": "/Users/Adam Davidson/.homebridge/applescript/ThomasMusicOn.scpt", "off": "/Users/Adam Davidson/.homebridge/applescript/ThomasMusicOff.scpt" }

MusicOn script:

` set AirplayDeviceName to "Thomas" set PlaylistName to "Sleep" set AirplayVolume to 10

activate application "iTunes"

tell application "System Events" tell application "iTunes" set visible of front browser window to true set the view of the front browser window to playlist PlaylistName end tell end tell

tell application "System Events" tell process "iTunes" to if exists then click menu item "Songs" of menu "Shuffle" of menu item "Shuffle" of menu "Controls" of menu bar 1 click menu item "On" of menu "Shuffle" of menu item "Shuffle" of menu "Controls" of menu bar 1 end if end tell

tell application "iTunes" set AirplayNames to (get name of AirPlay devices) set AirplayDevices to (get AirPlay devices) set AirplayToPlay to {} repeat with i from 1 to length of AirplayNames if item i of AirplayNames as string = AirplayDeviceName then set end of AirplayToPlay to item i of AirplayDevices end repeat set current AirPlay devices to AirplayToPlay end tell

tell application "iTunes" play playlist PlaylistName set the sound volume to AirplayVolume end tell `

The script works standalone without homebridge involved.

dansays commented 7 years ago

You may have to escape the space in your pathnames:

"on": "/Users/Adam\ Davidson/.homebridge/applescript/ThomasMusicOn.scpt"

JangoBritt commented 7 years ago

I tried that. \ doesn't appear to be a valid escape character for JSON, so that didn't work either.

I tried moving the scripts to a folder /applescript, but same error.

as an aside, I tried configuring an invalid filename in the config.json, and the error was the same, meaning it's nothing to do with the file path.

JangoBritt commented 7 years ago

I did a full reinstall, and it's working now. No idea why.

Thanks for the help