204
© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. #WWDC14 JavaScript for Automation Session 306 Sal Soghoian Product Manger Automation Technologies Services

JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

  • Upload
    lekhanh

  • View
    248

  • Download
    0

Embed Size (px)

Citation preview

Page 1: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

#WWDC14

JavaScript for Automation

Session 306 Sal Soghoian Product Manger Automation Technologies

Services

Page 2: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script
Page 3: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Automation in Mavericks

Notifications

Code signing

use statements

Script libraries

Speakable workflows

Page 4: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Automation in Yosemite

Code-signed workflows

Enhanced script libraries

Script progress indicators

Dictation commands

Page 5: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

JavaScript for Automation

Page 6: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Script Editor

Page 7: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script
Page 8: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Slider

Page 9: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Script

Slider

Page 10: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Script

Event Log

Slider

Page 11: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script
Page 12: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Compile

Page 13: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Run

Page 14: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Stop

Page 15: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Language

Page 16: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script
Page 17: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

AppleScript

Page 18: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

JavaScript

Page 19: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Language

Page 20: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script
Page 21: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Keynote = Application('Keynote')

documents = Keynote.documents

progress = $.NSProgress.currentProgressprogress.totalUnitCount = documents.length

destinationPath = $('~/Movies').stringByExpandingTildeInPath

for (i in documents) {document = documents[i]exportName = document.name().replace('.key','.m4v')document.export({

to: Path(destinationPath.js + '/' + exportName),as: 'QuickTime movie'

})progress.completedUnitCount = i

}

progress.completedUnitCount = documents.length

Script

Page 22: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Keynote = Application('Keynote')

documents = Keynote.documents

progress = $.NSProgress.currentProgressprogress.totalUnitCount = documents.length

destinationPath = $('~/Movies').stringByExpandingTildeInPath

for (i in documents) {document = documents[i]exportName = document.name().replace('.key','.m4v')document.export({

to: Path(destinationPath.js + '/' + exportName),as: 'QuickTime movie'

})progress.completedUnitCount = i

}

progress.completedUnitCount = documents.length

// Target app "Keynote"! Application("Keynote").documents.length! ! --> 3! /* Progress: 1 of 3 */! Application("Keynote").documents[0].name()! ! --> “New Product Design.key"! Application("Keynote").export([object ObjectSpecifier], {to:[object ObjectSpecifier], as:'QuickTime movie’})! /* Progress: 33% completed */

Event Log

Script

Progress Indicator

Page 23: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Keynote = Application('Keynote') !documents = Keynote.documents !progress = $.NSProgress.currentProgress progress.totalUnitCount = documents.length !destinationPath = $('~/Movies').stringByExpandingTildeInPath !for (i in documents) { document = documents[i] exportName = document.name().replace('.key','.m4v') document.export({ to: Path(destinationPath.js + '/' + exportName), as: 'QuickTime movie' }) progress.completedUnitCount = i } !progress.completedUnitCount = documents.length!

Event Log

Script

Progress Indicator

Page 24: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Keynote = Application('Keynote') !documents = Keynote.documents !progress = $.NSProgress.currentProgress progress.totalUnitCount = documents.length !destinationPath = $('~/Movies').stringByExpandingTildeInPath !for (i in documents) { document = documents[i] exportName = document.name().replace('.key','.m4v') document.export({ to: Path(destinationPath.js + '/' + exportName), as: 'QuickTime movie' }) progress.completedUnitCount = i } !progress.completedUnitCount = documents.length!

! Application("Keynote").documents[1].name()! ! --> “Wind Power.key”! /* Progress: 2 of 3 */! Application("Keynote").export([object ObjectSpecifier], {to:[object ObjectSpecifier], as:'QuickTime movie'})! /* Progress: 66% completed */

Event Log

Script

Progress Indicator

Page 25: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Keynote = Application('Keynote') !documents = Keynote.documents !progress = $.NSProgress.currentProgress progress.totalUnitCount = documents.length !destinationPath = $('~/Movies').stringByExpandingTildeInPath !for (i in documents) { document = documents[i] exportName = document.name().replace('.key','.m4v') document.export({ to: Path(destinationPath.js + '/' + exportName), as: 'QuickTime movie' }) progress.completedUnitCount = i } !progress.completedUnitCount = documents.length!

Event Log

Script

Progress Indicator

Page 26: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Keynote = Application('Keynote') !documents = Keynote.documents !progress = $.NSProgress.currentProgress progress.totalUnitCount = documents.length !destinationPath = $('~/Movies').stringByExpandingTildeInPath !for (i in documents) { document = documents[i] exportName = document.name().replace('.key','.m4v') document.export({ to: Path(destinationPath.js + '/' + exportName), as: 'QuickTime movie' }) progress.completedUnitCount = i } !progress.completedUnitCount = documents.length!

! Application("Keynote").documents[2].name()! ! --> "Community Projects.key"! Application("Keynote").export([object ObjectSpecifier], {to:[object ObjectSpecifier], as:'QuickTime movie'})! /* Progress: 3 of 3 */! /* Progress: 100% completed */// Stop targetingResult:3

Event Log

Script

Page 27: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script
Page 28: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script
Page 29: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script
Page 30: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

General Settings

Page 31: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Default Language

Page 32: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

AppleScript

Page 33: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

JavaScript

Page 34: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script
Page 35: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Script Menu

Page 36: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Script Menu

Script Menu

Page 37: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Formatting

Page 38: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Formatting

Page 39: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script
Page 40: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script
Page 41: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script
Page 42: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Language

Page 43: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Language

Page 44: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

LanguageAppleScript

Page 45: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

LanguageAppleScript

JavaScript

Page 46: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

LanguageAppleScript

JavaScriptObjective-C

Page 47: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script
Page 48: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Model Viewer

Page 49: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Suite

Page 50: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Suite

Methods

Page 51: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Suite

Class

Methods

Page 52: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Suite

Class

ElementsMethods

Page 53: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Suite

Class

Properties

ElementsMethods

Page 54: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Definition Viewer

Page 55: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Class

Properties

Elements

Methods

Page 56: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script
Page 57: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Script Editor

Page 58: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

JavaScript for Automation

David Steinberg Automation Engineer

Page 59: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

JavaScript for Automation

Application scripting

Libraries and applets

UI scripting

Using system APIs

Page 60: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Automation

Page 61: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

AutomationAutomate tasks

Page 62: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

AutomationAutomate tasks

Page 63: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

AutomationInteract with applications

Page 64: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

+ + +

AutomationInteract with applications

Page 65: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Demo

Page 66: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Automation

Page 67: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Cocoa Scripting

Automation

Page 68: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Cocoa Scripting

!

!

!

!

Object Model

!

!

!

!

Object Model

Automation

!

!

!

!

Object Model

Page 69: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Cocoa Scripting

!

!

!

!

Object Model

!

!

!

!

Object Model

!

!

!

!

Object Model

Automation

Page 70: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Apple EventsCocoa Scripting

!

!

!

!

Object Model

!

!

!

!

Object Model

!

!

!

!

Object Model

Automation

Page 71: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Apple EventsCocoa Scripting

!

!

!

!

Object Model

!

!

!

!

Object Model

!

!

!

!

Object Model

Automation

Page 72: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Apple Events

AppleScript Objective-C

Python

Ruby

Perl

Cocoa Scripting

!

!

!

!

Object Model

!

!

!

!

Object Model

!

!

!

!

Object Model

Automation

Page 73: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

AutomationObject model

Page 74: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

AutomationObject model

Page 75: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

application

application "Mail"

AutomationObject model

Page 76: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

application

inbox

application "Mail"inbox of

AutomationObject model

Page 77: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

application

inbox

messages

application "Mail"inbox of

AutomationObject model

Page 78: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

application

inbox

messages

message 1 message 2. . .

application "Mail"inbox ofmessage 2 of

AutomationObject model

Page 79: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

JavaScript

Page 80: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

JavaScript and Automation

Page 81: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

JavaScript and Automation

Cocoa Scripting

!

!

!

!

Object Model

!

!

!

!

Object Model

!

!

!

!

Object Model

Apple Events

Page 82: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

JavaScript and Automation

Cocoa Scripting

!

!

!

!

Object Model

!

!

!

!

Object Model

!

!

!

!

Object Model

Apple EventsJavaScript

CoreJavaScript AE Bridge

Page 83: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application Scripting

Page 84: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingApplication object

Page 85: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Name: Application('Safari')

Application ScriptingApplication object

Page 86: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Name: Application('Safari')

Bundle ID: Application('com.apple.mail')

Application ScriptingApplication object

Page 87: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Name: Application('Safari')

Bundle ID: Application('com.apple.mail')

Path: Application('/Applications/TextEdit.app')

Application ScriptingApplication object

Page 88: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Name: Application('Safari')

Bundle ID: Application('com.apple.mail')

Path: Application('/Applications/TextEdit.app')

Process ID: Application(763)

Application ScriptingApplication object

Page 89: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Name: Application('Safari')

Bundle ID: Application('com.apple.mail')

Path: Application('/Applications/TextEdit.app')

Process ID: Application(763)

Current Application: Application.currentApplication()

Application ScriptingApplication object

Page 90: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingSyntax

Page 91: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingSyntax

Properties: Safari.name

Page 92: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingSyntax

Properties: Safari.name

Elements: Safari.documents[0]

Page 93: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingSyntax

Properties: Safari.name

Elements: Safari.documents[0]

Commands: Safari.open(...)

Page 94: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingSyntax

Properties: Safari.name

Elements: Safari.documents[0]

Commands: Safari.open(...)

Classes: Safari.Document(...)

Page 95: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingGetting and setting properties

Page 96: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingGetting and setting properties

Safari = Application(‘Safari')

Page 97: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingGetting and setting properties

Safari = Application(‘Safari')

doc = Safari.document[0]

Page 98: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingGetting and setting properties

Safari = Application(‘Safari')

doc = Safari.document[0]

url = doc.url()

Page 99: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingGetting and setting properties

Safari = Application(‘Safari')

doc = Safari.document[0]

url = doc.url()

doc.url = 'http://apple.com'

Page 100: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingElement arrays

Page 101: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingElement arrays

Safari = Application('Safari')

Page 102: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingElement arrays

Safari = Application('Safari')

window = Safari.windows[0]

Page 103: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingElement arrays

Safari = Application('Safari')

window = Safari.windows[0]

window = Safari.windows['Apple']

Page 104: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingElement arrays

Safari = Application('Safari')

window = Safari.windows[0]

window = Safari.windows['Apple']

window = Safari.windows['#412']

Page 105: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Demo

Page 106: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingFiltering arrays

Page 107: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Mail = Application(‘Mail')

Application ScriptingFiltering arrays

Page 108: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Mail = Application(‘Mail')

jsEmails = Mail.inbox.messages.whose({subject:'JavaScript'})

Application ScriptingFiltering arrays

Page 109: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingSending commands

Page 110: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Mail = Application('Mail')

Application ScriptingSending commands

Page 111: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Mail = Application('Mail')

message = Mail.inbox.messages[0]

Application ScriptingSending commands

Page 112: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Mail = Application('Mail')

message = Mail.inbox.messages[0]

message.open()

Application ScriptingSending commands

Page 113: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Mail = Application('Mail')

message = Mail.inbox.messages[0]

message.open()

Mail.open(message)

Application ScriptingSending commands

Page 114: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Mail = Application('Mail')

message = Mail.inbox.messages[0]

message.open()

Mail.open(message)

Application ScriptingSending commands

response = message.reply({ replyAll: true, openingWindow: false })

Page 115: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingPaths

Page 116: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

TextEdit = Application('TextEdit')

Application ScriptingPaths

Page 117: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

TextEdit = Application('TextEdit')

path = Path(‘/Users/username/Desktop/foo.rtf')

Application ScriptingPaths

Page 118: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

TextEdit = Application('TextEdit')

path = Path(‘/Users/username/Desktop/foo.rtf')

TextEdit.open(path)

Application ScriptingPaths

Page 119: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingCreating objects

Page 120: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

TextEdit = Application(‘TextEdit')

Application ScriptingCreating objects

Page 121: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

TextEdit = Application(‘TextEdit')

doc = TextEdit.Document()

Application ScriptingCreating objects

Page 122: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

TextEdit = Application(‘TextEdit')

doc = TextEdit.Document()

TextEdit.documents.push(doc)

Application ScriptingCreating objects

Page 123: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

TextEdit = Application(‘TextEdit')

doc = TextEdit.Document()

TextEdit.documents.push(doc)

doc.text = 'Hello world’

Application ScriptingCreating objects

Page 124: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

TextEdit = Application(‘TextEdit')

doc = TextEdit.Document()

TextEdit.documents.push(doc)

doc.text = 'Hello world’

jsDoc = TextEdit.Document({text:'JavaScript for Automation'})

Application ScriptingCreating objects

TextEdit.documents.push(jsDoc)

Page 125: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Application ScriptingStandard additions

Page 126: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

app = Application.currentApplication()

Application ScriptingStandard additions

Page 127: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

app = Application.currentApplication()

app.includeStandardAdditions = true

Application ScriptingStandard additions

Page 128: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

app = Application.currentApplication()

app.includeStandardAdditions = true

app.beep(3)

Application ScriptingStandard additions

Page 129: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

app = Application.currentApplication()

app.includeStandardAdditions = true

app.beep(3)

app.say('Hello world')

Application ScriptingStandard additions

Page 130: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

app = Application.currentApplication()

app.includeStandardAdditions = true

app.beep(3)

app.say('Hello world')

app.displayAlert('Finished task')

Application ScriptingStandard additions

Page 131: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Libraries

Page 132: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

function log(message,format) { ... }

Libraries

Home Library Script Libraries toolbox.scpt

Page 133: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

function log(message,format) { ... }

Libraries

Home Library Script Libraries toolbox.scpt

toolbox = Library('toolbox') !

toolbox.log('hello world')

Page 134: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Applets

Page 135: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

AppletsEvent handlers

Page 136: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

AppletsEvent handlers

function run() { ... }

Page 137: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

AppletsEvent handlers

function run() { ... }

function openDocuments(docs) { ... }

Page 138: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

AppletsEvent handlers

function run() { ... }

function openDocuments(docs) { ... }

function printDocuments(docs) { ... }

Page 139: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

AppletsEvent handlers

function run() { ... }

function openDocuments(docs) { ... }

function printDocuments(docs) { ... }

function idle() { ... }

Page 140: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

AppletsEvent handlers

function run() { ... }

function openDocuments(docs) { ... }

function printDocuments(docs) { ... }

function idle() { ... }

function reopen() { ... }

Page 141: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

AppletsEvent handlers

function run() { ... }

function openDocuments(docs) { ... }

function printDocuments(docs) { ... }

function idle() { ... }

function reopen() { ... }

function quit() { ... }

Page 142: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Demo

Page 143: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

UI Scripting

Page 144: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

UI ScriptingBuilt on accessibility

Page 145: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

UI ScriptingBuilt on accessibility

Page 146: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

UI ScriptingBuilt on accessibility

System Events

Page 147: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

UI ScriptingBuilt on accessibility

System Events

UI Scripting

Page 148: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

UI ScriptingClicking and typing

Page 149: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

UI ScriptingClicking and typing

SystemEvents = Application('System Events’)

Page 150: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

UI ScriptingClicking and typing

SystemEvents = Application('System Events’)

notesUI = SystemEvents.processes[‘Notes']

Page 151: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

UI ScriptingClicking and typing

SystemEvents = Application('System Events’)

notesUI = SystemEvents.processes[‘Notes']

notesUI.windows[0].buttons[0].click()

Page 152: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

UI ScriptingClicking and typing

SystemEvents = Application('System Events’)

notesUI = SystemEvents.processes[‘Notes']

notesUI.windows[0].buttons[0].click()

Notes = Application('Notes') Notes.activate()

Page 153: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

UI ScriptingClicking and typing

SystemEvents = Application('System Events’)

notesUI = SystemEvents.processes[‘Notes']

notesUI.windows[0].buttons[0].click()

Notes = Application('Notes') Notes.activate()

SystemEvents.keystroke('m', { using: 'command down' })

Page 154: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Using System APIs

Page 155: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Using System APIsObjC and $

Page 156: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Using System APIsObjC and $

ObjC.wrap(...)

Page 157: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Using System APIsObjC and $

ObjC.wrap(...)

ObjC.unwrap(...) ObjC.deepUnwrap(...)

Page 158: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Using System APIsObjC and $

ObjC.wrap(...)

ObjC.unwrap(...) ObjC.deepUnwrap(...)

ObjC.import(...)

Page 159: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Using System APIsObjC and $

ObjC.wrap(...)

ObjC.unwrap(...) ObjC.deepUnwrap(...)

ObjC.import(...)

$.NSString

Page 160: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Using System APIsObjC and $

ObjC.wrap(...)

ObjC.unwrap(...) ObjC.deepUnwrap(...)

ObjC.import(...)

$.NSString

$('foo')

Page 161: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Calling methodsUsing System APIs

Page 162: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Calling methods

str = [[NSString alloc] initWithUTF8String:”bar”]; !

[str writeToFile:@"/tmp/foo" atomically:YES];

Using System APIs

Page 163: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Calling methods

str = [[NSString alloc] initWithUTF8String:”bar”]; !

[str writeToFile:@"/tmp/foo" atomically:YES];

Using System APIs

str = $.NSString.alloc.initWithUTF8String(‘bar') !

str.writeToFileAtomically('/tmp/foo', true)

Page 164: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Demo

Page 165: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Accessing propertiesUsing System APIs

Page 166: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Accessing properties

task = $.NSTask.alloc.init

Using System APIs

Page 167: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Accessing properties

task = $.NSTask.alloc.init

task.running

Using System APIs

Page 168: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Accessing properties

task = $.NSTask.alloc.init

task.running

task.launchPath = '/bin/sleep'

Using System APIs

Page 169: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Bridged nilUsing System APIs

Page 170: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Bridged nil

error = $()

Using System APIs

Page 171: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Bridged nil

error = $()

Using System APIs

doc = $.NSXMLDocument.alloc.initWithXMLStringOptionsError( xmlString, undefined, error )

Page 172: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Bridged nil

error = $()

Using System APIs

if (doc.isNil()) { $.NSLog(error.userInfo.description) }

doc = $.NSXMLDocument.alloc.initWithXMLStringOptionsError( xmlString, undefined, error )

Page 173: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

SubclassingUsing System APIs

Page 174: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Subclassing

ObjC.registerSubclass({

Using System APIs

})

Page 175: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Subclassing

ObjC.registerSubclass({ name: ‘AppDelegate',

Using System APIs

})

Page 176: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Subclassing

ObjC.registerSubclass({ name: ‘AppDelegate', superclass: ‘NSObject’,

Using System APIs

})

Page 177: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Subclassing

ObjC.registerSubclass({ name: ‘AppDelegate', superclass: ‘NSObject’, protocols: [‘NSApplicationDelegate'],

Using System APIs

})

Page 178: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Subclassing

ObjC.registerSubclass({ name: ‘AppDelegate', superclass: ‘NSObject’, protocols: [‘NSApplicationDelegate'],

Using System APIs

properties: { window: 'id' },

})

Page 179: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Subclassing

ObjC.registerSubclass({ name: ‘AppDelegate', superclass: ‘NSObject’, protocols: [‘NSApplicationDelegate'],

Using System APIs

properties: { window: 'id' }, methods: { 'applicationDidFinishLaunching:': { types: ['void', ['id']], implementation: function (notification) { $.NSLog('Application finished launching'); } } } })

Page 180: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Demo

Page 181: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Release notesUsing System APIs

Page 182: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Release notes

Binding C functions

Using System APIs

Page 183: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Release notes

Binding C functions

Explicit pass-by-reference

Using System APIs

Page 184: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Release notes

Binding C functions

Explicit pass-by-reference

Passing functions as blocks

Using System APIs

Page 185: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Where to Use It

Page 186: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

JavaScript for AutomationSystem-wide scripting

Page 187: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Script Editor

JavaScript for AutomationSystem-wide scripting

Page 188: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Script Editor

Applets/Droplets

JavaScript for AutomationSystem-wide scripting

Page 189: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Script Editor

Applets/Droplets

Script Menu

JavaScript for AutomationSystem-wide scripting

Page 190: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Script Editor Automator

Applets/Droplets

Script Menu

JavaScript for AutomationSystem-wide scripting

Page 191: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Script Editor Automator

Applets/Droplets

Script Menu

JavaScript for AutomationSystem-wide scripting

Services

Page 192: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Script Editor Automator

Applets/Droplets

Script Menu

JavaScript for AutomationSystem-wide scripting

osascript

Services

Page 193: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Demo

Page 194: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

JavaScript for AutomationSummary

Page 195: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

JavaScript for AutomationSummary

Built on JavaScriptCore and OSA

Page 196: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

JavaScript for AutomationSummary

Built on JavaScriptCore and OSA

Integrated system-wide

Page 197: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

JavaScript for AutomationSummary

Built on JavaScriptCore and OSA

Integrated system-wide

Offers many options for scripting

Page 198: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

JavaScript for AutomationCall to action

Page 199: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

JavaScript for AutomationCall to action

Script applications

Page 200: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

JavaScript for AutomationCall to action

Script applications

Make your applications scriptable

Page 201: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

JavaScript for AutomationCall to action

Script applications

Make your applications scriptable

Tell others to make their applications scriptable

Page 202: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

More Information

[email protected]

!

Documentation JavaScript for Automation Release Notes https://developer.apple.com

Apple Developer Forums http://devforums.apple.com

Page 203: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script

Lab

• Automation Lab Services Lab B Friday 12:45PM

Page 204: JavaScript for Automation - devstreaming.apple.comdevstreaming.apple.com/videos/.../306_javascript_for_automation.pdf · Automation in Yosemite Code-signed workflows Enhanced script