SlideShare a Scribd company logo


JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
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






JavaScript で OS X を自動操作
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




JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作


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"








JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
var hoge = function() {
debugger
console.log("hoge")
}
debugger
console.log("fuga")
hoge()
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
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:" "})
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
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)
}
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
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
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作


JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
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()
}
JavaScript で OS X を自動操作
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]
JavaScript で OS X を自動操作
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()}`);
})
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作




JavaScript で OS X を自動操作
JavaScript で OS X を自動操作




JavaScript で OS X を自動操作
var run = function(argv) {
console.log(`${argv[0]}`)
}
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作




JavaScript で OS X を自動操作


JavaScript で OS X を自動操作

More Related Content

PDF
Applescript
KEY
Giran Sieges - Applescript com @leohackin
PDF
Scripting OS X with Applescript, without Applescript
PDF
Cocoa勉強会#43-Blocksを使う
PDF
Xcode以外の開発環境 AppCodeの紹介
KEY
タスクを喰らうど!
PPTX
Text to-speech
PDF
Quick Application Development with Web Frameworks
Applescript
Giran Sieges - Applescript com @leohackin
Scripting OS X with Applescript, without Applescript
Cocoa勉強会#43-Blocksを使う
Xcode以外の開発環境 AppCodeの紹介
タスクを喰らうど!
Text to-speech
Quick Application Development with Web Frameworks

More from Tomokazu Kiyohara (15)

PDF
Google Cloud Platform を支える技術 …のごく一部
PDF
イベント継続のコツ
PDF
Web API をデバックするときに必要なたったひとつのこと
PDF
明日から使えるコーディングツール
PDF
Atom.io Quick Scripting
PDF
Text-Objects - vim's elegant function
PDF
LiveStyle for Vim - Quick start
PDF
こわくないプルリク
PDF
Github's HUB
PDF
対サイバー攻撃アラートシステム “DAEDALUS”(ダイダロス)の紹介
KEY
Beginner's Sinatra
KEY
Compact Web - Remind "web compression" -
KEY
Zen coding15min
KEY
USTREAMの視聴率を上げよう!
KEY
JavaScript Dynamic Loading
Google Cloud Platform を支える技術 …のごく一部
イベント継続のコツ
Web API をデバックするときに必要なたったひとつのこと
明日から使えるコーディングツール
Atom.io Quick Scripting
Text-Objects - vim's elegant function
LiveStyle for Vim - Quick start
こわくないプルリク
Github's HUB
対サイバー攻撃アラートシステム “DAEDALUS”(ダイダロス)の紹介
Beginner's Sinatra
Compact Web - Remind "web compression" -
Zen coding15min
USTREAMの視聴率を上げよう!
JavaScript Dynamic Loading
Ad

Recently uploaded (20)

PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
cuic standard and advanced reporting.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
Big Data Technologies - Introduction.pptx
PPTX
A Presentation on Artificial Intelligence
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Machine learning based COVID-19 study performance prediction
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Modernizing your data center with Dell and AMD
PDF
Electronic commerce courselecture one. Pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
The Rise and Fall of 3GPP – Time for a Sabbatical?
The AUB Centre for AI in Media Proposal.docx
Review of recent advances in non-invasive hemoglobin estimation
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Network Security Unit 5.pdf for BCA BBA.
cuic standard and advanced reporting.pdf
NewMind AI Weekly Chronicles - August'25 Week I
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Big Data Technologies - Introduction.pptx
A Presentation on Artificial Intelligence
MYSQL Presentation for SQL database connectivity
Dropbox Q2 2025 Financial Results & Investor Presentation
Advanced methodologies resolving dimensionality complications for autism neur...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Machine learning based COVID-19 study performance prediction
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Modernizing your data center with Dell and AMD
Electronic commerce courselecture one. Pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Ad

JavaScript で OS X を自動操作

  • 1.
  • 4. 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 
 

  • 5.
  • 7. 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 
 

  • 12.
  • 13. 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" 
 

  • 14.
  • 15.
  • 32. var hoge = function() { debugger console.log("hoge") } debugger console.log("fuga") hoge()
  • 37. 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:" "})
  • 40. 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) }
  • 43. 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)
  • 44. 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
  • 47.
  • 50. 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() }
  • 52. 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]
  • 54. 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()}`); })
  • 55. 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()}`); })
  • 62.
  • 63.
  • 65. var run = function(argv) { console.log(`${argv[0]}`) }
  • 74.