need help with using javascript for automation

Discussion in 'Mac Programming' started by edwinx, Jul 13, 2017.

  1. edwinx macrumors member

    Joined:
    Jul 6, 2010
    #1
    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,
     
  2. Toutou macrumors 6502a

    Toutou

    Joined:
    Jan 6, 2015
    Location:
    Prague, Czech Republic
    #2
    Plain Javascript is a client-side language that can't really do anything outside the browser.

    Tell us more about your project.
     
  3. 960design macrumors 68000

    Joined:
    Apr 17, 2012
    Location:
    Destin, FL
    #3
    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...html#//apple_ref/doc/uid/TP40014508-CH109-SW1

    Javascript server side stuff:
    https://nodejs.org/en/
     
  4. Toutou macrumors 6502a

    Toutou

    Joined:
    Jan 6, 2015
    Location:
    Prague, Czech Republic
    #4
    That's why I specifically stated "plain Javascript". Node.js is a wholly different beast.
     
  5. 960design macrumors 68000

    Joined:
    Apr 17, 2012
    Location:
    Destin, FL
    #5
    Gotcha... thought 'plain' was referring to JS only as in no external libraries such as jQuery.

    A non-blocking beast of awesome.
     
  6. edwinx thread starter macrumors member

    Joined:
    Jul 6, 2010
    #6

    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,
     
  7. 960design macrumors 68000

    Joined:
    Apr 17, 2012
    Location:
    Destin, FL
    #7
    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/
     
  8. edwinx thread starter macrumors member

    Joined:
    Jul 6, 2010
    #8
    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


     
  9. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #9
    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
     
  10. pikester macrumors newbie

    pikester

    Joined:
    Feb 27, 2009
    #10
    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
     

Share This Page