forked from JXA-Cookbook/JXA-Cookbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Using JavaScript for Automation
dtinth edited this page Oct 31, 2014
·
4 revisions
Why don't you open the Script Editor?
osascript -il JavaScript-
-imeans interactive mode -
-l JavaScriptspecifies the language. Otherwise, it is AppleScript. You probably don't want to use it 😛.
#!/usr/bin/env osascript -l JavaScript
function run(argv) {
console.log(JSON.stringify(argv))
}Services are handy utilities Automator workflows in Mac OS X. When you create a service, it will show in the "Services" menu in the menu bar. You can, for instance, create a service that renames files in batch using arbitrary JavaScript code.
Open Automator.app and create a new "Service". Drag the "Run JavaScript" action, then add your code.
Shell scripts and other scripts can run arbitrary JXA code using the osascript command line tool.
osascript -l JavaScript -e 'Application("iTunes").currentTrack.name()'The result of the last statement will be printed out, similar to when you call eval().
