Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JavaScript for Automation

JavaScript for Automation

NSEG 第57回勉強会 発表資料

Adfa46c35fd59858d262497800c68df4?s=128

Ryoichi Izumita

November 16, 2014
Tweet

Transcript

  1. @rizumita JavaScript for Automation Release Notes͔Β

  2. ͸͡Ίʹ ❖ MacͰͷࣗಈԽεΫϦϓτݴޠ͸AppleScript ❖ AppleScript͸͋·Γར༻͸޿͕͍ͬͯͳ͍ ❖ AppleScript͸ಛघͳߏจ ❖ Yosemite͔ΒJavaScript͕ར༻Մೳʹͳͬͨ ❖

    JavaScript for Automationͱݺ͹ΕΔ
  3. جຊ - AppleScript tell application "Safari" set theWindow to first

    window set theTab to current tab of theWindow do JavaScript "alert(document.title)" in theTab end tell
  4. جຊ - JavaScript safari = Application('Safari') window = safari.windows[0] tab

    = window.currentTab safari.doJavaScript('alert(document.title)', { in: tab })
  5. Application΁ͷΞΫηεํ๏ Application('Safari') // ໊લ Application('com.apple.safari') // όϯυϧID Application(‘/Applications/Safari.app') // ύε

    Application(763) // ϓϩηεID Application(‘eppc://127.0.0.1/Safari') // ϦϞʔτϚγʔϯ Application.currentApplication() // ΧϨϯτΞϓϦ
  6. ഑ྻཁૉ΁ͷΞΫηε // Index window = app.windows.at(0) window = app.windows[0] //

    Name window = app.windows.byName(‘New Window’) window = app.windows[‘New Window’] // ID window = app.windows.byId(256)
  7. ഑ྻͷϑΟϧλϦϯά windows.whose({query})Ͱߦ͏ɻ { name: 'JavaScript for Automation' } { _match:

    [ hoge.tabs[0].name, 'Apple' ] }
  8. ৚݅ͷࢦఆ { hoge: { filter: ‘Fuga’ } } _equals /

    ‘=' _contains / _beginsWith / _endsWith _greaterThan / ‘>' _greaterThanEquals / ‘>=‘ _lessThan / ‘<‘ _lessThanEquals / '<='
  9. and or not { _and: [ { name: 'Apple' },

    { size: { '<': 20 } }, ]} _and _or _not
  10. ΦϒδΣΫτͷ࡞੒ message = Mail.OutgoingMessage().make() message = Mail.OutgoingMessage({ subject: 'Hello world',

    visible: true }) para = TextEdit.Paragraph({}, 'Some text')
  11. Scripting Additions app = Application.currentApplication() app.includeStandardAdditions = true app.say('Hello world')

    app.displayDialog('Please enter your email address', { withTitle: 'Email', defaultAnswer: 'your_email@site.com' }) // ϝιουʹ͍ͭͯ͸ϥΠϒϥϦͷStandardAdditionsΛࢀর
  12. JavaScriptͷؔ਺ var safari = Application('Safari'); link = makeMarkdownLink(safari); safari.includeStandardAdditions =

    true safari.setTheClipboardTo(link) function makeMarkdownLink(aSafari) { var title = aSafari.doJavaScript('document.title', { in: safari.windows[0].currentTab() }); var url = aSafari.doJavaScript('document.URL', { in: safari.windows[0].currentTab() }); return '[' + title + '](' + url + ')'; }
  13. ࢀߟURL ❖ JavaScript for Automation Release Notes https://developer.apple.com/library/mac/ releasenotes/InterapplicationCommunication/RN- JavaScriptForAutomation/index.html