├── .gitignore ├── scripts ├── UpdateTableOfContents └── GenerateTableOfContents └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /wiki 2 | 3 | # created by git-ignore 4 | .DS_Store 5 | .AppleDouble 6 | .LSOverride 7 | 8 | # Icon must ends with two \r. 9 | Icon 10 | 11 | # Thumbnails 12 | ._* 13 | 14 | # Files that might appear on external disk 15 | .Spotlight-V100 16 | .Trashes 17 | 18 | -------------------------------------------------------------------------------- /scripts/UpdateTableOfContents: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | if [ ! -e wiki ] 4 | then 5 | git clone git@github.com:dtinth/JXA-Cookbook.wiki.git wiki 6 | else 7 | (cd wiki && git fetch && git reset --hard origin/master) 8 | fi 9 | 10 | if (cd wiki && git log -1 --oneline) | grep TOCBOT 11 | then 12 | echo "No update" 13 | exit 0 14 | fi 15 | 16 | scripts/GenerateTableOfContents 17 | (cd wiki && git commit -am 'TOCBOT: Update Table of Contents' && git push) 18 | 19 | 20 | -------------------------------------------------------------------------------- /scripts/GenerateTableOfContents: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | home = File.read('wiki/Home.md') 4 | sidebar = File.read('wiki/_Sidebar.md') 5 | 6 | sidetoc = [] 7 | 8 | home.gsub! %r{([\s\S]*?)} do 9 | name = $1 10 | url = "https://github.com/dtinth/JXA-Cookbook/wiki/#{name}" 11 | page = `curl --compressed "#{url}"` 12 | title = page.match(%r{]*>(.*?)})[1] 13 | contents = page.scan %r{]*href="(#[^"]+)"[^>]*>.*?(.*?)} 14 | toc = contents.map { |hash, title| "\n * [[#{title}|#{name}#{hash}]]" }.join 15 | sidetoc << %Q(\n * [[#{title}|#{name}]]) 16 | %Q(#{toc}) 17 | end 18 | 19 | sidebar.gsub! %r{()([\s\S]*)()} do 20 | %Q(#{$1}\n#{sidetoc.join}#{$3}) 21 | end 22 | 23 | File.write('wiki/Home.md', home) 24 | File.write('wiki/_Sidebar.md', sidebar) 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [JavaScript for Automation Cookbook][wiki] 2 | ================================== 3 | 4 | JavaScript for Automation is a new thing in Mac OS X Yosemite. 5 | It allows you to control applications using JavaScript language. How awesome! 6 | 7 | However, [its documentation](https://developer.apple.com/library/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/index.html) covers the basics of using JavaScript to interact with the Open Scripting Architecture. 8 | For many tasks in scripting, there's a lot to figure out, and many different documentations to refer to. 9 | 10 | So I created this JavaScript for Automation cookbook that features a lot of examples, such as: 11 | 12 | - How to [display alert, prompt and confirm dialogs](https://github.com/dtinth/JXA-Cookbook/wiki/User-Interactions). 13 | - How to [run shell scripts](https://github.com/dtinth/JXA-Cookbook/wiki/Shell-and-CLI-Interactions). 14 | - How to [create a command-line script](https://github.com/dtinth/JXA-Cookbook/wiki/Using-JavaScript-for-Automation#creating-a-shebang-script) (shebang script) and read `argv` arguments, how to create a [Mac OS X service](https://github.com/dtinth/JXA-Cookbook/wiki/Using-JavaScript-for-Automation#creating-a-mac-os-x-service), or how to [invoke the REPL](https://github.com/dtinth/JXA-Cookbook/wiki/Using-JavaScript-for-Automation#running-the-repl-read-eval-print-loop). 15 | - How to [use Browserify to be able to require npm modules](https://github.com/dtinth/JXA-Cookbook/wiki/Exotic-Recipes#requiring-commonjs-and-npm-modules-using-browserify) in JXA. 16 | 17 | Where it makes sense, I try to link to the official documentation as much as possible so you can dive deeper. 18 | 19 | For ease of editing and contribution, the cookbook's contents are on the [wiki][]. 20 | 21 | [![Enter Wiki](https://svg-buttons.herokuapp.com/button/plain.svg?button_width=400&text=Enter+Wiki)][wiki] 22 | 23 | [wiki]: https://github.com/dtinth/JXA-Cookbook/wiki 24 | --------------------------------------------------------------------------------