xilopaint Posted November 20, 2017 Share Posted November 20, 2017 (edited) I am thinking about to learn JXA so rewriting my Things workflow, originally written in AppleScript, feels a good opportunity. How do you guys see JXA in comparison to AS? Should I expect some gain in performance? Is there any workflow library for JXA? Maybe rewriting my workflow would not worth the effort if there isn't any workflow library for Alfred feedback generation in XML or JSON. Edited September 27, 2018 by xilopaint Link to comment
deanishe Posted November 20, 2017 Share Posted November 20, 2017 JavaScript is a much more pleasant language to use than AppleScript (what isn't?), but the actual API for talking to applications is even more demented (it is at least "native" in AppleScript, not a nasty hack), almost never documented (you spend a lot of time trying to guess what methods and attributes are called), and often simply doesn't work with a given application. You certainly don't need a library to generate feedback in JavaScript. JSON basically is JavaScript. You only need to call JSON.stringify() on a JS object. Personally, I'd say it's probably not worth rewriting a workflow that already works except as a learning exercise. It's quite possible you'll run into something you need to do API-wise that simply doesn't work in JXA. AppleScript and JavaScript are both fundamentally crappy languages. My approach is almost always to use them solely to extract data from/add data to applications and use a more sensible language for the rest of the workflow. xilopaint and vitor 2 Link to comment
xilopaint Posted November 20, 2017 Author Share Posted November 20, 2017 25 minutes ago, deanishe said: JavaScript is a much more pleasant language to use than AppleScript (what isn't?), but the actual API for talking to applications is even more demented (it is at least "native" in AppleScript, not a nasty hack), almost never documented (you spend a lot of time trying to guess what methods and attributes are called), and often simply doesn't work with a given application. What do you mean with "almost never documented"? I thought JXA had a dictionary similarly to AppleScript. Link to comment
vitor Posted November 20, 2017 Share Posted November 20, 2017 10 minutes ago, deanishe said: I'd say it's probably not worth rewriting a workflow that already works except as a learning exercise. I agree with @deanishe’s whole post, but wanted to reiterate this point. JXA can be more capable than AppleScript. My get_title_and_url script is a good example — read the comments, where I explain why the JXA version is superior. But if the AppleScript version didn’t have the limitation it has, spending time on the JXA version would have been almost1 pointless. In terms of resources, I recommend both the JXA Cookbook (most web searched will lead here, anyway) and the Mac Automation Scripting Guide which is an official resource and shows how to do the same things in both languages. 1. It’s not pointless in the sense that if you want to integrate the code into your own script, instead of calling it stand-alone, it’s (naturally) preferred that it’s in the language you’re writing. xilopaint 1 Link to comment
vitor Posted November 20, 2017 Share Posted November 20, 2017 25 minutes ago, xilopaint said: What do you mean with "almost never documented"? I thought JXA had a dictionary similarly to AppleScript. But that only tells your how to interact with a particular app (and often poorly), not how to use the language itself. When you want to do something even slightly complex, you’re relegated to a bunch of StackOverflow answers and obscure forums, where you’ll have to mix and match answers to do what you want. Frequently I see code of the form tell some_app some_action end tell When tell some_app to some_action does the same more clearly and with less code. But the people doing the multi-line version aren’t even aware the single-line version exists (in all cases I’ve found). You eventually pick that up in someone else’s code and realise you could have benn doing the same yourself. deanishe 1 Link to comment
xilopaint Posted November 20, 2017 Author Share Posted November 20, 2017 (edited) 39 minutes ago, vitor said: But that only tells your how to interact with a particular app (and often poorly), not how to use the language itself. But deanishe talked about "the actual API for talking to applications". Edited November 20, 2017 by xilopaint Link to comment
deanishe Posted November 20, 2017 Share Posted November 20, 2017 57 minutes ago, xilopaint said: What do you mean with "almost never documented"? I thought JXA had a dictionary similarly to AppleScript. Yeah, there's a dictionary, but it's not generally a great help. Apple-style docs are typically great if you already know how everything works and just forgot the name of a parameter, but they're useless if you've no idea what's going on. Like, how do you do a whose clause in JXA? At least with AppleScript, Google will usually turn something up. Link to comment
xilopaint Posted October 3, 2018 Author Share Posted October 3, 2018 Hey @deanishe and @vitor, sorry for bugging again with this thread but now I see Objective-C has also a dictionary to interact with applications. Would it be a better option than AppleScript and JXA? Link to comment
deanishe Posted October 4, 2018 Share Posted October 4, 2018 What does “better” mean? Link to comment
xilopaint Posted October 4, 2018 Author Share Posted October 4, 2018 (edited) 20 minutes ago, deanishe said: What does “better” mean? If you could pick only one language to interact with macOS applications what would it be and why? Edited October 4, 2018 by xilopaint Link to comment
deanishe Posted October 4, 2018 Share Posted October 4, 2018 None of those three weird languages… Link to comment
xilopaint Posted October 4, 2018 Author Share Posted October 4, 2018 3 minutes ago, deanishe said: None of those three weird languages… And how can you do that without the API made for those three languages? Link to comment
deanishe Posted October 4, 2018 Share Posted October 4, 2018 (edited) Using a bridge, for example. Do you have anything concrete in mind? There usually isn't such a thing as a "better language" in isolation from an actual problem you're trying to solve. Edited October 4, 2018 by deanishe Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now