Last active
August 31, 2022 17:25
-
-
Save zakuroishikuro/a6a1c85dbe1faeee2439 to your computer and use it in GitHub Desktop.
JXAでSafari, Chrome, Firefoxを操作する際の違い ref: http://qiita.com/zakuroishikuro/items/194223d63b0f95ab7a63
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const DELAY = 3; | |
var Chrome = Application("Google Chrome"); | |
var window = Chrome.windows[0]; //最前面のウィンドウを取得 | |
while(window.exists()){ //無限ループ (ウィンドウが開いてなければ実行しない) | |
window.tabs().forEach(function(tab, i){ | |
// タブ切り替え | |
window.activeTabIndex = i + 1; | |
delay(DELAY); | |
// 更新 | |
tab.reload(); | |
delay(DELAY); | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const DELAY = 3; | |
var Firefox = Application("Firefox"); | |
var window = Firefox.windows[0]; //最前面のウィンドウを取得 | |
SystemEvents = Application("System Events"); | |
while(window.exists()){ //無限ループ (ウィンドウが開いてなければ実行しない) | |
// タブ切り替え | |
Firefox.activate(); | |
delay(0.3); //アクティブになるまで少し待つ | |
SystemEvents.keystroke("]", {using:["command down", "shift down"]}); | |
delay(DELAY); | |
// 更新 | |
Firefox.activate(); | |
delay(0.3); //アクティブになるまで少し待つ | |
SystemEvents.keystroke("r", {using:"command down"}); | |
delay(DELAY); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const DELAY = 3; | |
var Safari = Application("Safari"); | |
var window = Safari.windows[0]; //最前面のウィンドウを取得 | |
while(window.exists()) { //無限ループ (ウィンドウが開いてなければ実行しない) | |
window.tabs().forEach(function(tab){ | |
// タブ切り替え | |
window.currentTab = tab; | |
delay(DELAY); | |
// 更新 | |
tab.url = tab.url(); | |
delay(DELAY); | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = Application.currentApplication(); | |
app.includeStandardAdditions = true; | |
var date = app.doShellScript("date"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Safari = Application("Safari"); | |
var doc = Safari.Document().make(); | |
var win = Safari.windows[doc.name()]; | |
//URL移動 | |
win.currentTab.url = "http://qiita.com" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> Firefox = Application("Firefox") | |
=> Application("Firefox") | |
>> Firefox.windows.length | |
=> 10 | |
>> Firefox.documents() | |
=> [] | |
>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> Firefox = Application("Firefox") | |
=> Application("Firefox") | |
>> Firefox.windows.length | |
=> 10 | |
>> Firefox.documents() | |
=> [] | |
>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
varFirefox = Application("Firefox"); | |
Firefox.windows[0].document(); | |
//=> undefined | |
Firefox.windows[0].properties(); | |
//=> {"document":null, "closeable":true, "zoomed":true, "class":"window", "index":1, "visible":true, "name":"Yahoo! JAPAN", "modal":false, "miniaturizable":true, "titled":true, "id":6188, "miniaturized":false, "floating":false, "resizable":true, "bounds":{"x":0, "y":23, "width":1280, "height":709}, "zoomable":true} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> Firefox = Application("Firefox") | |
=> Application("Firefox") | |
>> Firefox.windows.length | |
=> 10 | |
>> Firefox.documents() | |
=> [] | |
>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
varFirefox = Application("Firefox"); | |
Firefox.windows[0].document(); | |
//=> undefined | |
Firefox.windows[0].properties(); | |
//=> {"document":null, "closeable":true, "zoomed":true, "class":"window", "index":1, "visible":true, "name":"Yahoo! JAPAN", "modal":false, "miniaturizable":true, "titled":true, "id":6188, "miniaturized":false, "floating":false, "resizable":true, "bounds":{"x":0, "y":23, "width":1280, "height":709}, "zoomable":true} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Safari.doJavaScript("location.reload()", {in:tab}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Chrome.execute(tab, {javascript:"location.reload()"}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Terminal = Application("Terminal"); | |
var tab = Terminal.windows[0].selectedTab(); // SafariはcurrentTab。名前統一してくれ | |
Terminal.doScript("echo 'hi.'", {in:tab}); | |
var newTab = Terminal.doScript("echo 'hi new window.'"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tab.url = tab.url(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Chrome.execute(tab, {javascript:"location.reload()"}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment