The title says it all. Is there a way to write macros in JavaScript to achieve a similar functionality to that of Autoit? I just would want to manipulate files on my own computer (offline) and could easily do it with autoit, but since I am currently learning JavaScript -- plan to develop in Node.js -- I figure it wouldn't hurt to get the extra practice.
Thanks guys!
Use an application which supports JavaScript as a shell scripting language, such as the following:
JsRoboKey
PowershellJS
PowerChakra
RemoteNodeJS
JScript + WSH
JavaScript Shell Scripting with JSC
QtScript: QScriptEngine
Part I: How to Choose a JavaScript Engine for iOS and Android Development - OpenAphid-Engine
nodejs has a module which do autoit things --
nodejs install autoit
var au = require('autoit');
au.Init();
au.Run("notepad.exe");
au.WinWait("[Class:Notepad]");
au.Send("Hello, autoit & nodejs!");
NodeJS is a very powerfull platform, it is extensible and opensource.
There is no problem to run local scripts to do everything you need using JavaScript (see standard FileSystem library docs). You can also try to look in NPM(NodeJS package manager).
Assuming you have AutoIt installed (say in folder C:\AU3) and this folder in the PATH, you can add
extension '.AU3' to the PATHEXT environment variable, and create an AutoIt script called, say,
hello.au3 with just a silly line:
MsgBox(0, "Warning", "Hello, World!")
Now, simply typing the command 'hello' will execute the script, displaying the silly message in a modal message box.
Next, create an equally silly Node.js script, say, MyWarn.js - in the same folder:
var oCP = require("child_process");
console.log("Starting...");
var oNP = oCP.execSync("hello");
console.log("Done.");
Assuming Node is also in the PATH, try this command:
node MyWarn
So ... we get the benefits of Node (for its jit), and the benefits of AutoIt (for its GUI handling.)
The problem is getting the two to communicate. Personally, I use a RamDisk to pass small files...
Javascript can't write to a file on your local machine remotely.. Its almost the same as HTML in a view model.
It can however perform some executions of other scripts via AJAX for example. But thats on server again.
It might be worth a look to read on server && client side differences.
im not 100% sure but node might offer another outlet on this but it would still be server side.. Not locally.
The Server - This party is responsible for serving pages and handling the logic | Code behind.
The Client - This party requests pages from the Server, and displays them to the user. On most cases, the client is a web browser.
The User - The user uses the Client in order to surf the web, fill in forms, watch videos online, etc.
Related
I have read several posts on this site that ask similar questions but the key difference is they involve a client and a server. For my use, this is not the case. I am simply pasting a file directory on my computer into my browser in order to view a local HTML file, packed with CSS and some jQuery.
I've been looking around and the answers I've found are "No; a client can not write to a server", and "No; a server can not write to a client". But there is no answer to "can a client write to a client with JavaScript?"
Use case:
I'm building a webapp (website? JS app?) as a college project for a stock management tool that will be locally hosted and never connect to the internet. Sure, I could knock one together in python in a couple hours, but I wouldn't learn anything. I need to create an access a txt file containing an array of the current stock of all the items so that when the application is loaded, the user doesn't have to manually enter anything but the changes to stock levels.
Honestly, I'm a beginner at JS and JQ and I'm only going off of what makes sense based on a mix of HTML and Python that I know.
Maybe PHP would be the better option for this particular option, or maybe JS will work well enough.
You still won't be doing client-to-client, your browser will just act as though the local file system is the server using the file:// protocol which means the same rules about a "client" (the browser) cannot write to a "server" (your local file system) apply.
If you wan't to be able to write an application that can interface directly with the filesystem, then look into something like Electron which is essentially an augmented website that gives you APIs to interact with the actual computer the app is being run on, including filesystem stuff.
So, I'm making a quiz, and I've been wanting to save my answers to a text file. I want to use "Node.js", and I'm worried about this: They only offer an installer to install Node.js on your computer. Since I'm not working with servers or anything like that, and I'm just a hobbyist, the people I might first give this to may not have Node.js installed on their computer. Please do note that this is for a website, not a program.
Is this kind of thing possible to do without the use of a hosting service or a server? :
const lib = require('./libraries/NODE')
If it is, how would I do it?
Thanks for any help!
There are two options for you:
I would suggest using something like Electron- which will wrap the node runtime for you - https://www.electronjs.org/docs/tutorial/first-app which you can distribute to people. This will open up all the nodejs related functionality and more for you.
Another answer at SO though old, suggests using window.name vs writing out text files - Javascript/HTML Storage Options Under File Protocol (file://)
You cannot import nodejs runtime into the browser running on a file protocol.
I need to run a Javascript file for a relatively long time(maybe about 5 weeks or so at one time), without it stopping or being interrupted. Currently the script is a client side script which connects to the server and receives data via Sockjs. There is no HTMl/GUI. There is only some computation.
I need to make sure the client always stays connected to the server all the time. I need to be able to run some script from the command line which is like forever.js. I have tried porting the javascript to node.js but it doesnt work. It only works in the browser. I have tried reading the file and doing an eval but none of it works. Are there any other options open for me? I have tried phantomJS but that doesnt work too. I have looked at How can I use a javascript library on the server side of a NodeJS app when it was designed to run on the client? and Load "Vanilla" Javascript Libraries into Node.js but I reapeatedly get SockJS is not defined. I guess the problem lies deep in the library and is not a simple fix.
Could anyone give me some pointers? What are my other options? Whats the best way to test a client javascript library which seems to work only on the browser?
This is the repo I am using :
https://github.com/sockjs/sockjs-client
It doesnt seems to be running on node. I tried to replace the script tag with require, and download the sock.js into a separate file and use it.
There are "headless" browser modules available. These produce a virtual browser environment that can be programatically controlled. The primary use of these is to do unit/integration testing of browser side code without actually running a browser:
Phantomjs
Slimerjs
These might fit your needs. You can create a nodejs script that will load the said code in a virtual browser page.
I need to set up automatic remote updates for my app built on nodeJS (not the nodeJS itself).
In my specific case I can't distribute my app as SaaS, so I have to share a copy of app with each client.
I've checked related topics here, but haven't found helpful ones.
Here are a few related questions: one, two
I don't know how to set it up, but I have a few ideas:
old-school way (?) :
use unix cron + shell (or php) script to make «check-request» to «update-server»,
stop nodeJS instance,
replace files with newest ones from tarball,
run nodeJS instance with my app : from shell(?)
It may work if I use my own server, but how can I do the same on, for example, Heroku ?
Overall, it seems weird a bit.
two nodeJS instances way (?) :
use unix cron + another nodeJS app which checks updates on update-server,
then stop one node instance from another && update files
start one nodeJS instance with my app from another : how???
— Is here something else?
— How do folks solve that problem?
— How to realize, for instance, functionality like «Update manager» in Wordpress for nodeJS based app?
What you're talking about is CI (continuous integration), there are many tools that can help you in the process but they essentially do the same thing.
Detect a change in the code
Pull changes
Build the project
Run tests if there are any
Deploy to the server
— How do folks solve that problem?
Folks use Jenkins, bamboo and many other auto deployment systems.
If you're using node with pm2 you can use kinematic that has that build in (one-click deployment feature)
Is it possible to list the files in a directory using only javascript? To clarify, I mean list the files on the server, not the files on the clients computer. For instance:
www.domain.com/files/
contains 4 images (.jpg)
Can I make an extra page (www.domain.com/files/list.html) that lists those 4 files using javascript?
No, Javascript doesn't have access to the filesystem. Server side Javascript is a whole different story but I guess you don't mean that.
Very late to this party, but my google search for this exact request led me here.
The answer is "not really", but I've found the frankenstein of hacks elsewhere: If +Indexes is (or can be) enabled in the .htaccess for the folder containing the files you want to list, then use XMLHTTPRequest with the folder name as the url (which will return an html page listing the files).
I don't know if you architecture allows it but ikf you can install and use node.js as its node API mentions, you can interact with the filesystem by requiring the fs module.
This is the environment Node.js relies on:
Node eventually wants to support all
POSIX operating systems (including
Windows with MinGW) but at the moment
it is only being tested on Linux,
Macintosh, and Solaris. The build
system requires Python 2.4 or better.
V8, on which Node is built, supports
only IA-32 and ARM processors. V8 is
included in the Node distribution. To
use TLS, OpenSSL are required. There
are no other dependencies.
You can run It side-by-side with another web app. and this will avoid blocking your web application if the interaction with the filesystem takes too long.
It is generally not a good idea to access client computer files via javascript for security reasons, however i suspect you can use the File System Object for that. I am not sure about browser-compatibility for that, it should work in IE only probably though.
You need to use server-side languages such as PHP, ASP.Net, JSP, etc
JavaScript runs inside a host environment. So if the host provides a facility to list files in this manner, then yes. But in the typical scenario where JavaScript is running in a browser with default configuration, no.