Successfully reported this slideshow.
Your SlideShare is downloading. ×

JavaScript で OS X を自動操作

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Applescript
Applescript
Loading in …3
×

Check these out next

1 of 75 Ad
Advertisement

More Related Content

More from Tomokazu Kiyohara (15)

Recently uploaded (20)

Advertisement

JavaScript で OS X を自動操作

  1. 1. 

  2. 2. 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 
 

  3. 3.
  4. 4. 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 
 

  5. 5.
  6. 6. 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" 
 

  7. 7.
  8. 8.
  9. 9. var hoge = function() { debugger console.log("hoge") } debugger console.log("fuga") hoge()
  10. 10. 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:" "})
  11. 11. 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) }
  12. 12. 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)
  13. 13. 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
  14. 14.
  15. 15. 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() }
  16. 16. 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]
  17. 17. 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()}`); })
  18. 18. 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()}`); })
  19. 19. 
 

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

  24. 24.

×