Linking python script to add-on main code

Hello. I would like to use api win32 for creating an hidden file on win os. It seems not possible using js / nodejs. With python, importing the api, it is possible (with SetFileAttributes routine and FILE_ATTRIBUTE_HIDDEN parameter).

So how can I link a python script to the main js code? Can you please give me some reference about this matter? I ve found nothing on the web.

You can use js-ctypes - https://github.com/Noitidart/ostypes/issues/1

And then you can use CreateFile and then OS.Constants.Win.FILE_ATTRIBUTE_HIDDEN -

https://dxr.mozilla.org/mozilla-central/source/nsprpub/pr/tests/testfile.c#670-699

It might be possible with OS.File.setPermissions I’ll check.

You should have 0 need for python. Here aresome docs on js-ctypes:

I don’t recall how, but I’m pretty sure you can use nsIFile. Although the new methods for file system is OS.File and nsIFile is getting deperecated in various scopes.

1 Like

This is how you do it with OS.File:

OS.File.setPermissions(
        OS.Path.join(OS.Constants.Path.desktopDir, 'my hidden file.txt'),
          {
            winAttributes: {
                hidden: true
            }
        }
)
.then(x => console.log('success:', x), y => console.error('failure:', y));

This will set the file on the deskto named my hidden file.txt to be hidden. Here are the other winAttributes:

https://dxr.mozilla.org/mozilla-central/source/toolkit/components/osfile/modules/osfile_win_front.jsm#1204-1227

1 Like

Thank you very much

Keep up the great work! :slightly_smiling: