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

JavaScript for Automation

JavaScript for Automation

NSEG 第57回勉強会 発表資料

Ryoichi Izumita

November 16, 2014
Tweet

More Decks by Ryoichi Izumita

Other Decks in Programming

Transcript

  1. جຊ - 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
  2. جຊ - JavaScript safari = Application('Safari') window = safari.windows[0] tab

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

    Application(763) // ϓϩηεID Application(‘eppc://127.0.0.1/Safari') // ϦϞʔτϚγʔϯ Application.currentApplication() // ΧϨϯτΞϓϦ
  4. ഑ྻཁૉ΁ͷΞΫηε // 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)
  5. ৚݅ͷࢦఆ { hoge: { filter: ‘Fuga’ } } _equals /

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

    { size: { '<': 20 } }, ]} _and _or _not
  7. Scripting Additions app = Application.currentApplication() app.includeStandardAdditions = true app.say('Hello world')

    app.displayDialog('Please enter your email address', { withTitle: 'Email', defaultAnswer: '[email protected]' }) // ϝιουʹ͍ͭͯ͸ϥΠϒϥϦͷStandardAdditionsΛࢀর
  8. 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 + ')'; }