Atom is not defined


#1

TL;DR My question is: how do i access the atom instance in scripts outside init.coffee?

i am completely new to atom, and fiddling with coffeescript in the init package. To avoid testing my partial scripts by exiting+re-entering all the time, i added the “script” package and try to run my test.coffee file. However, it seems that script can’t access the atom classes i.e. i get the error

ReferenceError: atom is not defined

on the 1-line script:
atom.getVersion()

I tried to change working directory in the “script” package options to the directory with the atom exe and the init.coffee but without succes.

Apologies if this is not the appropriate forum to ask this question


#2

Did you require/import atom?


#3

I think so. As mentioned i am a beginner, but i tried to put either of these on top without change:
{Atom} = require ‘atom’
{atom} = require ‘atom’


#4

What script does is execute a command-line instruction to a binary that can parse the code. I know of no way to import Atom’s globals from an external script.

What you can do is to use a package like preview to look at what your CoffeeScript will look like as JavaScript, and then use the developer tools console (View -> Developer -> Toggle developer tools and select the Console tab) to run the code (just paste it in, and if it’s valid it will run).


#5

OK Thanks for answer!