Closed helmutgranda closed 6 years ago
Electron is running with weird values for __dirname
and __filename
, so working with absolute paths is a pain. Instead, you can load your scripts in plain text and execute them as a text script, intead of file. For example, you can check osx-define plugin, that is running python script as a plain text.
Thanks for the pointer! I am not sure if this will become a bigger issue down the road since the work around is feasable for items where we can feed the right path, however there will be instances where a third party module may already have it backed into itself and unless we branch the specific module it won't be usable.
I installed the Define plugin to test it and I am not seeing any definitions, after a quick search it does look like it is a known issue: https://github.com/KELiON/cerebro-osx-define/issues/2
Yep, there is another issue, but it is not related to this question (it is realted to some framework used in python, but in your case you're using built-in osascript
). But if you're interested you can see how it works here:)
Thanks @KELiON, I tried to build from source to see I could find a work around to this issue and noticed that you are already doing some of that work through WebPack:
node: {
__dirname: false,
__filename: false
},
https://github.com/webpack/webpack/issues/1599
But I gave up and just decided to use raw-loader https://github.com/webpack-contrib/raw-loader. It works for me and we'll see if no one else needs this feature where they can't use the source from a third party module 👍
Issue
I am trying to use https://www.npmjs.com/package/node-osascript in order to execute commands on MacOS, single commands work great, where things break is when I need to feed the path to an external file that needs to be processed and executed.
using
__dirname
from node, the root directory is evaluated as such/
which may be OK in some instances but after looking more in depth at the application osascript can't find the file provided. However, if I feed manually the full path/users/user/Developer/plugin/file
things work as expected. I have tried different methods in order to get the full path for my plugin but everything returns as/
.If there is a plugin out there that is already using external sources properly please just point me to the plugin and I can study how that is achieved.