Skip to content

Instantly share code, notes, and snippets.

@zakuroishikuro
Last active August 31, 2022 17:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zakuroishikuro/a6a1c85dbe1faeee2439 to your computer and use it in GitHub Desktop.
Save zakuroishikuro/a6a1c85dbe1faeee2439 to your computer and use it in GitHub Desktop.
JXAでSafari, Chrome, Firefoxを操作する際の違い ref: http://qiita.com/zakuroishikuro/items/194223d63b0f95ab7a63
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);
});
};
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);
};
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);
});
};
var app = Application.currentApplication();
app.includeStandardAdditions = true;
var date = app.doShellScript("date");
var Safari = Application("Safari");
var doc = Safari.Document().make();
var win = Safari.windows[doc.name()];
//URL移動
win.currentTab.url = "http://qiita.com"
>> Firefox = Application("Firefox")
=> Application("Firefox")
>> Firefox.windows.length
=> 10
>> Firefox.documents()
=> []
>>
>> Firefox = Application("Firefox")
=> Application("Firefox")
>> Firefox.windows.length
=> 10
>> Firefox.documents()
=> []
>>
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}
>> Firefox = Application("Firefox")
=> Application("Firefox")
>> Firefox.windows.length
=> 10
>> Firefox.documents()
=> []
>>
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}
Safari.doJavaScript("location.reload()", {in:tab});
Chrome.execute(tab, {javascript:"location.reload()"});
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.'");
Chrome.execute(tab, {javascript:"location.reload()"});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment