New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File IO? #79
Comments
Hi @fluffynuts , You can check the example/test.js file that call windows popup for example I will update this issue when fs is updated |
@fluffynuts I added the fs-std module for simple fs support, it will be improved soon see 94689cf |
That helps, but I still can't compile my simple script: var fs = require("fs-std"); // use with nectar.js
//var fs = require("fs"); // use with node.js
var process = require("process");
var inputFile = fs.readFileSync(process.argv[2]);
var output = '{"items": [';
var first = true;
inputFile = inputFile.toString();
inputFile = inputFile.split('\n');
for(var i = 0; i < inputFile.length; i++) {
if(inputFile[i] !== "") {
if(!first) {
output += ",";
} else {
first = false;
}
var subitem = {
uid: inputFile[i],
type: "",
title: inputFile[i],
subtitle: process.argv[3],
arg: inputFile[i],
autocomplete: inputFile[i],
valid: true,
icon: {
type: "fileicon",
path: "~/Desktop"
}
};
output += JSON.stringify(subitem);
}
}
console.log(output + "]}"); It processes a list of names in a file and presents it to an Alfred Script filter. The resulting JSON file is large, so a compiled version would be preferable. |
@raguay i will check it |
Thanks. Looking forward to a solution. It'll make this a great way to build cli utilities. I've been using Haskel, but I'm constantly having issues with linked libraries. |
@raguay I added an example in the examples folder named I Updated NectarJS to make it working, should work with version v0.6.68 |
Working for me. I have the argument in the split with single quotes and it
will not compile that way. Changing to double quotes (like you had in the
examples) and it is now working. Thanks so much. This will be my main way
to do Alfred scripts going forward. Thanks!
…On Tue, Jun 30, 2020 at 10:26 PM Adrien THIERRY ***@***.***> wrote:
@raguay <https://github.com/raguay> I added an example in the examples
folder named read_file_to_json.js
I Updated NectarJS to make it working, should work with version v0.6.68
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#79 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAS7JR7X7I7RRGPFB6KC5X3RZH72TANCNFSM4NEW6HGA>
.
|
I just optimized the code some more and it will compile, but not run? It looks like you can't push items onto an array? What would be the recommened way? The new code is: var fs = require("fs-std");
var process = require("process");
var inputFile = fs.readFileSync(process.argv[2]);
var output = {};
output.items = [];
inputFile = inputFile.toString().split("\n");
for(var i = 0; i < inputFile.length; i++) {
if(inputFile[i] != "") {
var subitem = {
uid: inputFile[i],
type: "",
title: inputFile[i],
subtitle: process.argv[3],
arg: inputFile[i],
autocomplete: inputFile[i],
valid: true,
icon: {
type: "fileicon",
path: "~/Desktop"
}
};
output.items.push(subitem);
}
}
console.log(JSON.stringify(output)); By doing the JSON.stringify once, I'm figuring it would save a lot of time! |
@raguay the array.push function does not exist at the moment, I will add it |
@raguay it should be okay, i added array.push method, could you try again ? |
Hi,
I'm still getting errors on running:
```
»»»» ./fileToAlfred -- allcleaners.txt 'TextSoap'
0|09:02:28
[!] Fatal error, object is not a function
```
I think it thinks the push function is an object. I did "npm -g update
nectarjs" to update to the latest version: 0.6.72
…On Wed, Jul 1, 2020 at 9:49 PM Adrien THIERRY ***@***.***> wrote:
@raguay <https://github.com/raguay> it should be okay, i added array.push
method, could you try again ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#79 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAS7JRZMYBNA6JVSMWOE5Z3RZNEGXANCNFSM4NEW6HGA>
.
|
BTW: I'm having to delete the `.nectar` directory each time to clear out
old bugs.
…On Thu, Jul 2, 2020 at 9:05 AM Richard Guay ***@***.***> wrote:
Hi,
I'm still getting errors on running:
```
»»»» ./fileToAlfred -- allcleaners.txt 'TextSoap'
0|09:02:28
[!] Fatal error, object is not a function
```
I think it thinks the push function is an object. I did "npm -g update
nectarjs" to update to the latest version: 0.6.72
On Wed, Jul 1, 2020 at 9:49 PM Adrien THIERRY ***@***.***>
wrote:
> @raguay <https://github.com/raguay> it should be okay, i added
> array.push method, could you try again ?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#79 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAS7JRZMYBNA6JVSMWOE5Z3RZNEGXANCNFSM4NEW6HGA>
> .
>
|
@raguay : Chaining functions is not working yet, i add it to the roadmap, You can make your script working by removing the
|
Okay. Composing works, chaining doesn't work. Got it. It's working now.
Thanks.
Richard
…On Thu, Jul 2, 2020 at 3:09 PM Adrien THIERRY ***@***.***> wrote:
@raguay <https://github.com/raguay> : Chaining functions is not working
yet, i add it to the roadmap,
You can make your script working by removing the toString() call on
inputFile :
inputFile = inputFile.split("\n");
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#79 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAS7JR3TNKUXBSYXRWPJGY3RZQ6CPANCNFSM4NEW6HGA>
.
|
@raguay function chaining is now available, |
The sub object bug is corrected, your code is working good now |
Wow. It is really working great and so fast! Thank you so much. It is also
compiling in a directory with a path that has special characters just fine.
Thanks so much for the quick fixes. My Alfred workflow is now almost
instant!
Richard
…On Fri, Jul 3, 2020 at 3:50 PM Adrien THIERRY ***@***.***> wrote:
The sub object bug is corrected, your code is working good now
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#79 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAS7JR36EUMENUSYMXGPNO3RZWLVXANCNFSM4NEW6HGA>
.
|
Did you try to compile with the |
No, I didn't know about that flag. It's very fast with the defaults. I'll
try that as well. Thanks.
…On Fri, Jul 3, 2020 at 4:40 PM Adrien THIERRY ***@***.***> wrote:
Did you try to compile with the --preset speed flag ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#79 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAS7JR77S6HPM6PBZ2OHFMDRZWRSFANCNFSM4NEW6HGA>
.
|
Okay, that did seem to make it faster. Wow. Great work.
On Fri, Jul 3, 2020 at 6:06 PM Richard Guay <notifications@github.com>
wrote:
… No, I didn't know about that flag. It's very fast with the defaults. I'll
try that as well. Thanks.
On Fri, Jul 3, 2020 at 4:40 PM Adrien THIERRY ***@***.***>
wrote:
> Did you try to compile with the --preset speed flag ?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#79 (comment)>,
> or unsubscribe
> <
https://github.com/notifications/unsubscribe-auth/AAS7JR77S6HPM6PBZ2OHFMDRZWRSFANCNFSM4NEW6HGA
>
> .
>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#79 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAS7JR3T53IJZ5FSY44AWVTRZW3U7ANCNFSM4NEW6HGA>
.
|
Hi
I see that support for "fs" is still on the way, so just asking out of curiosity -- is there currently any other way to do file IO?
The text was updated successfully, but these errors were encountered: