Skip to content

Instantly share code, notes, and snippets.

@whobutsb
Created October 19, 2018 15:29
Show Gist options
  • Save whobutsb/45717993373a5ecafd64cd91c5fcf384 to your computer and use it in GitHub Desktop.
Save whobutsb/45717993373a5ecafd64cd91c5fcf384 to your computer and use it in GitHub Desktop.
Play and Pause SoundCloud with JXA
// grab the chrome object
var chrome = Application("Google Chrome");
// grab all of the chrome windows
var windows = chrome.windows;
// loop through the chrome windows
for(i = 0; i < windows.length; i++){
// grab all of the tabs for the window
var tabs = windows[i].tabs;
// loop through the tabs
for(j = 0; j < tabs.length; j++){
// grab the url for the tab
var url = tabs[j].url();
// check to see if the tab url matches "soundcloud.com"
if(url.match(/soundcloud.com/)){
// in the tab lets execute some javascript
tabs[j].execute({
// select the .playControl div and click it!
javascript: "document.querySelector('.playControl').click();"
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment