75

JavaScript で OS X を自動操作

Embed Size (px)

Citation preview

set urls to {"https://www.google.co.jp","http://www.yahoo.co.jp","https://www.apple.com"} set countOfUrls to count urls

tell application "Safari" activate tell window 1 set firstTab to current tab repeat with i from 1 to countOfUrls set URL of document 1 to (item i of urls) if i = countOfUrls then exit repeat set current tab to (make new tab) end repeat set current tab to firstTab end tell end tell

var urls = [ "https://www.google.co.jp", "http://www.yahoo.co.jp", "https://www.apple.com" ]

var safari = Application("Safari") safari.activate() var w = safari.windows[0] var firstTab = w.currentTab() for (var i in urls) { w.tabs[0].url = urls[i] if (i == urls.length - 1) { break } var _tab = new safari.Tab() w.tabs.push(_tab) w.currentTab = _tab } w.currentTab = firstTab

var safari = Application("Safari") safari.activate()

var w = safari.windows[0] console.log(w.tabs[0].url())

w.tabs[0].url = "https://www.google.co.jp"

var hoge = function() { debugger console.log("hoge") }

debugger

console.log("fuga")

hoge()

var app = Application.currentApplication() app.includeStandardAdditions = true

app.displayAlert(" ")

var Hello = function() { try { app.displayDialog(" ") console.log(" ") } catch(e) { console.log(" ") } }

Hello() Hello()

app.displayNotification(" ",{withTitle:" ",subtitle:" "})

var app = Application.currentApplication() app.includeStandardAdditions = true

var stdout = app.doShellScript("whoami") console.log(stdout)

try { stdout = app.doShellScript("ls NOT_EXIST") } catch (e) { var stderr = e.message console.log(stderr) }

var safari = Application("Safari") safari.activate()

delay(2)

var se = Application("System Events") se.keystroke("l", {using:"command down"})

delay(2)

se.keystroke("http://www.google.com")

delay(2)

se.keyCode(76)

var se = Application("System Events")

var safari = Application("Safari") safari.activate()

delay(1)

var toolbar = se.uiElements["Safari"].uiElements[0].uiElements[4]

toolbar.uiElements[1].click()

delay(1)

toolbar.uiElements[5].click()

delay(1)

se.keyCode(125) // down arrow

delay(1)

se.keyCode(76) // enter

var se = Application("System Events")

if(se.uiElementsEnabled()) {

console.log(" OK") } else { console.log(" NG") // var pref = Application("System Preferences"); var pane = pref.panes.byId("com.apple.preference.security") pane.anchors["Privacy_accessibility"].reveal(); pref.activate() }

var se = Application("System Events")

var app = se.uiElements[TARGET_APP_NAME].uiElements[TARGET_APP_NAME] var main_area = app.uiElements[5].uiElements["Box"].uiElements[0]

var table1 = main_area.uiElements[0].uiElements[0] var tab = main_area.uiElements["Peers"] var table2 = main_area.uiElements[7].uiElements[0].uiElements[0]

var se = Application("System Events")

se.uiElements[TARGET_APP_NAME].entireContents().forEach(function(v, i, a){

console.log(`${Automation.getDisplayString(v)}`);

console.log(`${v.name()} / ${v.description()}`); })

var se = Application("System Events")

se.uiElements[TARGET_APP_NAME].entireContents().forEach(function(v, i, a){

console.log(`${Automation.getDisplayString(v)}`);

console.log(`${v.name()} / ${v.description()}`); })

var run = function(argv) { console.log(`${argv[0]}`) }