jxa-userland / jxa Goto Github PK
View Code? Open in Web Editor NEWJavaScript for Automation(JXA) packages for TypeScript/Node.js.
License: MIT License
JavaScript for Automation(JXA) packages for TypeScript/Node.js.
License: MIT License
TypeScript will refuse to allow Application
to be called when esModuleInterop
is true
:
A namespace-style import cannot be called or constructed, and will cause a failure at runtime.
I don't have my head around it enough to understand if that means that the library should or can be adjusted to make it work, or if it means that it inherently can't build sensible code when esModuleInterop
is true
. In my case, my project was fine turning it off, but it would be useful to have a note in the Readme, since the problem was hard to track down.
Many thanks for sharing System Events.sdef.
How can this be used in VSCode with my JavaScript for Automation (JXA) files to provide intellisense?
Hi, your system looks great, but I can't get it work in Visual Studio Code.
I did the following:
import "@jxa/global-type";
// your JXA application
var userName = Application("System Events").currentUser().name();
But as I type "App" I do not see the autocomplete as shown in your GIF, nor do I see it when I type "Application("Sys"
Can you please help me get your system running in VSC?
Thanks.
Hi there!
This might be a dumb question but when importing @jxa/global-type on my .ts file and then compiling I get this error:
node_modules/@jxa/global-type/src/index.d.ts:8:11 - error TS2403: Subsequent variable declarations must have the same type. Variable 'Application' must be of type 'typeof Application', but here has type 'typeof Application & object'.
8 const Application: typeof Application_ & object;
~~~~~~~~~~~
Found 1 error.
seems like its causing conflict with this two definition type..
Is it necessary to check that Application is also an object?
Hi @azu, can you put types
into DefinitelyTyped?
Hi. Great work ๐
This issue might be more of a how do you do this in TypeScript, but here it goes. I think that the my use case would be interesting to others, so at least we could end up with some documentation.
I would like to add type declarations for 'non-core' types. Core as I understand it being the applications bundled with osx and defined in types/src/core . And they are manually added as return types for the Application
function, right?
As an example I would like to add declarations for Emacs
. I'm able to generate the .d.ts files from the .sdef file. But I'm not sure how include this file to work well with the rest of the jxa types.
Is there a way to "inject" this into the current setup or would it require changes?
Furthermore do you see a way of automating this. E.g. automatically discovering .sdef's in the Application folder and generating .d.ts files on the fly? Or would it be better to include these types in a package under the @jxa
org?
Can you provide an example of how to pass arguments to a run
function?
We tried this and a few other things:
const g = 'hello ';
// This function is JXA
return run((g) => {
const sys = Application("System Events");
return g + sys.currentUser().name();
});
The argument just comes in as 'undefined'.
In a related question, how can we call another defined function
from within the run
function?
Great library by the way, very helpful.
Hello, I just upgrade from 1.3.4
to 1.3.6
and find out that everything crashed because JXA is not able to read [].includes
.
I couldn't find any mention in the changelogs.
Do I miss something?
I got the error
"Can't find variable: _babel_runtime_corejs3_core_js_stable_instance_includes__WEBPACK_IMPORTED_MODULE_9___default"
I'm not an expert in sdef or the underlying APIs here, but children elements of classes are a pretty big gap in the generated type definitions.
For example, the System Events application (Application('System Events')
) has at least 4 defined child elements:
In most (all?) cases, these are accessible in at least 3 ways:
Application('System Events').processes(); // returns array
Application('System Events').processes['TextEdit']; // alias for processes.byName('TextEdit')
Application('System Events').processes[0]; // alias for processes.at(0)
If the generated types just included these methods for accessing children, it would make this 1000% more useful for UI automation. System Events relies heavily on child elements.
Thanks!
If you want to improve your editor for JSX, use @jxa/global-type. You can just import @jxa/global-type and you can introduce typing and auto complete for JSX.
Thanks, I had some good time today trying this library.
I'd like to better understand something.
Once I create my useful script, I'd like to execute it with a keyboard shortcut, something that is achievable in other ways with by using Services of the Automator app and associating the keyboard shortcut.
How do I do that after I have my script working in node?
var appIcon = $.NSWorkspace.sharedWorkspace.iconForFile('/System/Applications/TextEdit.app');
$.CFShow(appIcon);
// OUTPUT:
// <NSImage 0x7fdfea675180 Size={32, 32}
// RepProvider=<NSImageISIconRepProvider:0x7fdfe66046a0
// icon:<ISBundleIcon: 0x7fdfea673bc0>
// Bundle URL: file:///System/Applications/TextEdit.app/
// type: (null)
// tag: (null)
// tag class: (null)
// reps:(faulting)>
//>
Can't get the correct icon.
Please forgive me if some of my terminology is incorrect, I'm fairly new to JXA and I haven't been able to find much documentation on it.
I'm using this project in a TypeScript application and it's working great - thank you for such a cool idea and execution.
I've run into an issue with setting read-write variables. The current typings are fine for retrieving an attribute such as .index()
const windowIndex = safariWindow.index()
But there doesn't seem like there is a way to set the attribute without TS complaining. The two ways of setting that I am aware of are
safariWindow.index = 0
safariWindow.index.set(0)
I have had a think and I don't believe we can make a TS type to satisfy both the function call getter and the direct assignment setter, so I propose new interfaces that can be added to the .d.ts files for ReadOnly and ReadWrite attributes.
e.g.
export interface ReadWrite<T> {
(): T;
set: (value: T) => void;
}
...
index: ReadWrite<number>;
If this would be a useful and acceptable change for you, I'd be happy to do the work and make a PR.
I propose a command for creating .d.ts
files from .app
containers, like the ones in /Applications
.
npx @jxa/sdef-to-dfs /Applications/Safari.app
This will write a .d.ts
to the cwd with the name Safari.d.ts
.
First, thanks for building and sharing a terrific tool! ๐
I can't wait to start using it.
However, I need help. Can you please provide detailed, step-by-step, instructions on how to install your JXA autocomplete into Visual Studio Code?
Thanks.
when i call the app.systemInfo().IPv4Address
, it returns undefine, but app.systemInfo().ipv4Address
is woking fine. but use app.systemInfo().ipv4Address have type error.
First, let me give you many, many thanks for providing this tool.
I hope to use it to provide autocomplete in Visual Studio Code (VSC) for many of the third party apps (like Microsoft Outlook, Evernote, and Keyboard Maestro, and more) and many of the AppleScript Scripting Libraries (like Shane Stanley's "Myriad Tables Lib").
I have several questions:
My first question is about installation, using this command you provided:
npm install @jxa/sdef-to-dts
Where do I install this? What folder do I need to be in so that it is available to all folders and workspaces of VSC?
You provide this command to convert .sdef and .app files
$ npx @jxa/sdef-to-dts /Applications/Safari.app --output ./safari.d.ts
Two Questions:
Many thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.