ElectronJS - adding folder to favorites [macOS] - node.js

I am wondering if there is a way to add a folder to Favorites using Node?
I've found this issue, but the solution does not work anymore.
Basically the file that I'm interested in is located in:
/Users/USER_NAME/Library/Application\ Support/com.apple.sharedfilelist
The thing is I do not know how to modify it...

You can use try os module. Very easy to use.
Here is an example:
const home = require("os").homedir(); // This will get your OS based Home directory
const dirToSave = `${home}/Desktop/output.csv`; // Now you can add file or folder to any tree directory of home directory.
fs.writeFile(`${dirToSave}`, {csvData}, function(err, stat) {
if (err) throw err;
console.log("file saved");
});

There is a file that you need to edit
You can edit the sidebar on Mac using the com.apple.sidebarlists.plist preference file. The items will be in the favoriteitems dictionary.
The items you see are all set to being AlwaysVisible. You need to edit that file to add your own file.
I will give some links that might help you.
About the com.apple.sidebarlists.plist file, http://www.thexlab.com/faqs/finder.html
Finding the com.apple.finder.plist, https://discussions.apple.com/thread/4122582
Another post, https://apple.stackexchange.com/questions/139305/how-can-i-add-new-folders-to-the-favorites-in-the-finder-sidebar
About editing a file in Electron
There are tutorials about how to edit files with Electron, you can start from this example,
https://ourcodeworld.com/articles/read/106/how-to-choose-read-save-delete-or-create-a-file-with-electron-framework

What I've done is I wrote a python script based on the resource that #Royson posted in this question's comments (click).
It's available under a gist:
https://gist.github.com/Ancinek/6d6e34791c5a8674275560ae118848c7
Currently possible to add/remove one file at a time.
I will be creating a binary for this so it can be run without the need to installing the pyobjc on the user's machine - will post the update soon after I find out how to actually do this.
Hope this helps somebody!

Related

How to delete all txt files within directory NodeJs

I need to delete only the txt files within a directory (multiple levels). I'd hazard a guess that it's possible with fs-extra...
https://github.com/jprichardson/node-fs-extra
But I can't find a solution without specifying the individual file name.
I was hoping to solve it with the following...
fse.remove('./desktop/directory/*.txt')
but unfortunately the asterisk wouldn't select all... as I then could have done something like the following...
fse.remove('./desktop/directory/sub1/*.txt')
fse.remove('./desktop/directory/sub1/sub2/*.txt')
fse.remove('./desktop/directory/sub1/sub2/sub3/*.txt')
fse.remove('./desktop/directory/sub1/sub2/sub3/sub4/*.txt')
Not the cleanest I know... But it's all I've got.
Any help or suggestions on this would be appreciated. Thanks.
If you are using rimraf, You can try this.
const rimraf = require('rimraf');
rimraf.sync('**/*.txt');
rimraf accept glob as the first parameter.
If you want to use it asynchronously, you can even write
rimraf('**/*.txt', options, () => {
console.log('deleted')
})
Though fs-extra uses rimraf internally to delete the file.
What about this?
fse.remove('./desktop/directory/**/*.txt')
Adding ** means to include all sub-directories

Automate PDF contents using nightwatch/Cucumber

I am using nightwatch/NodeJs using cucumber for Automation. I have a lot of areas where PDF's are generated and needs to be verified. Is there any way by which I can verify PDF contents which are downloaded including text/Images etc??
Thanks in advance.
You can use the pdfjs-dist package to read the contents of a PDF. In my experience it has worked most of the time. I have had a few instances where it returned no content even though I could visibly see that the file had text in it. I haven't tried to dig in to see why that was but the majority of the time it has worked for me without issue. Also, I have only used it to verify text. I haven't tried to use it for images so I'm not sure if it can do that. You can find more details here.
This will get you as far as getting all the text into an array. What you do with it from there is up to you.
pdfjs.getDocument('path/to/your/file.pdf').then(function(document) {
document.getPage(1).then(function(page) {
page.getTextContent().then(function(text) {
const allText = text.items.map(function(s) { return s.str }).concat('');
//console.log(allText);
});
});
});

Using a Twig Extension

I am trying to use teh Twig i18n Extension.
As far as I can tell the file I need is here:
https://github.com/fabpot/Twig-extensions/blob/master/lib/Twig/Extensions/Extension/I18n.php
Now I am not quite sure where to save this file
I have Twig in a folder called includes/lib (/includes/lib/Twig). I see a folder Extension under Twig. Do I save it here?
After I save it, do I need to do a "require_once" to the file or will Twig_Autoloader do the job for me?
I am not using Symfony2
Thanks
Craig
Here is the complete answer that worked for me:
Copy the file in Twig-Verzeichnis (extract i18n.zip in Twig).
For the I18n extension it would be Twig/Extensions/Extension/I18n.php
Eventually add other files requred by I18n. You will see what these are by the error messages that come. I had to add "Twig/Extensions/Node/Trans.php" and "Twig/Extensions/TokenParser/Trans.php".
In your config file add the following:
// Set language to German
putenv('LC_ALL=de_DE');
setlocale(LC_ALL, 'de_DE');
// Specify location of translation tables
bindtextdomain("project_de_DE", "./locale");
// Choose domain
textdomain("projectl_de_DE");
Register the Twig Extension
$twig->addExtension(new Twig_Extensions_Extension_I18n());
Create the directory locale/de_DE/LC_MESSAGES
Create the PO file (the easisest is to have a sample file to start from)
Open the file in a normal text editor (be sure to use utf-8 encoding) and start translating
Open the PO-Datei with PoEdit (www.poedit.net/)
Save to locale/de_DE/LC_MESSAGES (a MO-Datei will be created).
Add the translation to the appropriate places in the Twig-Template with
{% trans 'Text in the original language' %}`
You need to register this extension with Twig:
$twig->addExtension(new Twig_Extensions_Extension_I18n());
If your installation is configured correctly, the autoloader should do the job of including the file. If not, you could include the file manually or make the installation with composer.
It seems the "proper" way to install these extensions without Composer is as follows:
Download a release from https://github.com/fabpot/Twig-extensions/releases
Copy the contents of the lib/ directory somewhere to your project
include the file .../Twig/Extensions/Autoloader.php
Register autoloader: Twig_Extensions_Autoloader::register();
Continue as explained in the doc: http://twig.sensiolabs.org/doc/extensions/i18n.html

saving to /home/user/Documents in different locales / languages

In my linux python app for Fedora I want to save user's work to /home/user/Documents/MyCoolApp/TheirGreatWork.txt
But I am not sure how to find the "Documents" folder if the user is not using English as their default language.
What is the right way to determine the right path so that files go in their "Documents" folder.
EDIT
Here is a which comes up if you change locales... showing how paths can get easily changed.
I'd use the subprocess module to get the output of the command xdg-user-dir DOCUMENTS. For example:
import subprocess
documents_dir = subprocess.check_output(["xdg-user-dir", "DOCUMENTS"])
print documents_dir # This is what you're looking for.
There is no right way as the user may have changed their locale, which (fortunately) does not rename the directory. If you want a fixed place for files managed by your app, use ~user/.MyCoolApp or let the user specify the directory.

Open Files Created with BSAVE in QuickBasic?

I have some files that were created using BSAVE in QuickBasic. I'm wondering how I can load/view these files?
I received assistance over at the FreeBasic forums. Its easy to do if you download and install the FreeBasic compiler / IDE. Here is the relevant thread:
http://www.freebasic.net/forum/viewtopic.php?t=12554&postdays=0&postorder=asc&start=0
Essentially, it loads the image using BLOAD like one normally would and then BSAVEs it as a BMP. I suppose it would be pretty easy to create an app. that did this by just prompting for source and output files...
I would try installing pcpaint (free) http://www.shdon.com/software/pcpaint
Change the extension to .PIC and try to open it. Apparently this program used bsave to save images with the extention .pic.
Hope this works!

Resources