mikaelbr / node-osascript

A stream for Apple Open Scripting Architecture (OSA) through AppleScript or Javascript
MIT License
50 stars 5 forks source link

Error after Electron packager #6

Open kcampion opened 7 years ago

kcampion commented 7 years ago

Hi,

The module "osascript" works perfectly under dev mode into an Electron project (with the command line #electron .), but after build it with electron-packager (with the command line electron-packager . MyProject --platform=darwin --arch=x64 --version=1.3.5 --overwrite), the module fails. Any idea why?

This is the source code I use (works under dev, fails after packager):

var osascript = require('osascript').eval;

var script = 'tell application \"Terminal\"'+"\n"+
'  set newTab to do script'+"\n"+
'end tell';

osascript(script, { type: 'AppleScript' }, function (err, data) {
    console.log('osascript data:');
    console.log(data);
    if (err) {
        console.log('osascript error:');
        console.log(err);
    }
});

Console displays this:

osascript data:
null
osascript error:
Object {code: 1, signal: null}

The same source code works after packager if the script variable is equal to: var script = 'get volume settings';

My node version: v4.5.0 My electron version: v1.3.5

bradydowling commented 7 years ago

Also would be interested to hear more about this. I just started using this yesterday for an Electron app I'm building and it has been working fine while testing but I haven't tried packaging it quite yet. I'll report results when I do.

kcampion commented 7 years ago

I wait for your results.

bradydowling commented 7 years ago
screen shot 2016-12-01 at 8 36 44 pm

This works fine before it's packaged. Not sure how to view the console from within the packaged app but happy to provide any other info that would be helpful.

node: v0.12.7 (not sure why I'm so outdated) electron-packager: 5.1.0 electron-prebuilt: 0.36.0

I'll try other version later.

bradydowling commented 7 years ago

Same results with Node 6.9.1.

Jonovono commented 7 years ago

Also trying to figure this out. I was able to log my production app using electron-log

Everytime I try to run Applescript from a file I get the error:

Error: osascript: /Users/jordan/Desktop/plusaroo/dist/mac/Plusaroo.app/Contents/Resources/app.asar/app/refreshSpotify.applescript: No such file or directory

The file is definitely there though. I unpacked my app.asar file and can see it. 👁 👁

mikaelbr commented 7 years ago

I'm not sure why it's not working on inline scripts. I haven't tested this out in Electron my self. By the issue with NOENT i belive is due to the asar packing. Asar packs all files to a flat structure to avoid too long paths. As such the path it self changes. You can avoid the issue by excluding the script files from being packed by asar: https://github.com/electron/asar#excluding-multiple-resources-from-being-packed

bradydowling commented 7 years ago

@mikaelbr I actually see this same error when I build without using asar. I can try with exclude but it seems like it's not an asar issue.