need help with using javascript for automation

edwinx

macrumors member
Original poster
Jul 6, 2010
50
0
Hi,

I am trying to learn how to use Javascript for automation but having trouble and having trouble finding some good resources with examples as well.

Do you have any examples that you can recommend to me?

Thanks,
 

960design

macrumors 68030
Apr 17, 2012
2,820
831
Destin, FL
Plain Javascript is a client-side language that can't really do anything outside the browser.

Tell us more about your project.
Whoa there sir... it would seem you are very behind in your javascript thinking. I use it both server and client side as do most of the online sites you visit. Apple is replacing AppleScript with Javascript, well sort of.

Here is some of the documents for Javascript for Automation:
https://developer.apple.com/library/content/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/OSX10-10.html#//apple_ref/doc/uid/TP40014508-CH109-SW1

Javascript server side stuff:
https://nodejs.org/en/
 

edwinx

macrumors member
Original poster
Jul 6, 2010
50
0
Plain Javascript is a client-side language that can't really do anything outside the browser.

Tell us more about your project.

I want to use OSX Javascript to help me automate formatting some text and inputting it into Numbers.

I take daily notes in the Notes app. Each note is 1 day. I will have multiple entries in each note separated by client name and time and other details. I then need to copy paste this info and put it into a spreadsheet into pre formatted cells, etc

right now, I am doing this manually but I think it should be possible to use javascript, some reg expression to find "read" my notes, then paste them into the cells.

Is that possible? In my head, I think it is possible so I am trying to see how far I can get using javascript. Also thinking this will allow me to learn Javascript for use in OSX and for use in web apps too.

I will have to format my entries in a specific way.

something like this:

<entry>
<startTime></startTime>
<issue></issue>
<troubleShooting></troubleShooting>
<resolution></resolution>
<endTime></endTime>
</entry>

e.g.

<entry>
<startTime>15:00</startTime>
<issue>user cannot access network drive</issue>
<troubleShooting>
- network drive not mapped
- checked permissions and found incorrect permissions
- corrected permissions, user can access drive now
</troubleShooting>
<resolution>
- resolved issue by correct network drive permissions
</resolution>
<endTime>15:30</endTime>
</entry>

Maybe use Javascript to read this into memory and then put it into an array?
Then switch over to Numbers, and paste each piece of info into cells. The spreadsheet can be open already or the script can open it.

Is that possible or is that too much for Javascript to do?

Thanks,
 

960design

macrumors 68030
Apr 17, 2012
2,820
831
Destin, FL
Is that possible or is that too much for Javascript to do?
Absolutely possible. Pretty sure, nothing is impossible with Javascript. I would use Electron.io to build a quick local app. This would remove the reliance on Notes, Numbers and copy pasting, ect. I would have it check for internet connection and save everything to an offsite server in the background, while also saving locally for speed and workflow within internet restricted environments.

Javascript example:
http://www.sbs.com.au/theboat/
 

edwinx

macrumors member
Original poster
Jul 6, 2010
50
0
I use the Notes app because I would enter info using my phone or computer and because it’s synced between my 2 devices, it works with my current workflow.

So I take it that even though JavaScript can do it, it’s probably the hard way of doing it.

I’m trying to think what is the best way to get started


Absolutely possible. Pretty sure, nothing is impossible with Javascript. I would use Electron.io to build a quick local app. This would remove the reliance on Notes, Numbers and copy pasting, ect. I would have it check for internet connection and save everything to an offsite server in the background, while also saving locally for speed and workflow within internet restricted environments.

Javascript example:
http://www.sbs.com.au/theboat/
 

superscape

macrumors 6502a
Feb 12, 2008
920
214
East Riding of Yorkshire, UK
Hi,

Much as I don't want to get drawn into the "AppleScript will be dead in X months/years/decades" debate (which has been ongoing for as long as I can remember - and one day will be true), you may be better off trying to automate apps on macOS with AppleScript.

Although you certainly *can* use JavaScript nowadays, it's still much more common to use AppleScript and you're more likely to find useful examples online. Such as: https://macosxautomation.com/applescript/firsttutorial/index.html
 

pikester

macrumors newbie
Feb 27, 2009
27
0
If you are using Numbers, why not just use it to directly enter the data? It can handle syncing across devices like Notes (Google Docs will do that too). You might find that much easier to implement and use than the process you are trying to implement.

If you want to stick to Javascript, you'll first need to parse the data (I'll skip that for now). Once you have data you want to paste on the clipboard, you can use this Javascript to do it:
https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript