Skip to content

Instantly share code, notes, and snippets.

@rjames86
Last active April 3, 2017 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjames86/6f847988f829387832e892731c0ce614 to your computer and use it in GitHub Desktop.
Save rjames86/6f847988f829387832e892731c0ce614 to your computer and use it in GitHub Desktop.
Safari = Application('Safari');
Safari.includeStandardAdditions = true;
SystemEvents = Application('System Events')
SystemEvents.includeStandardAdditions = true;
activeAppName = SystemEvents.processes.whose({frontmost:true}).at(0).name();
activeApp = Application(activeAppName);
function run(){
frontWindow = Safari.windows.at(0);
SystemEvents.activate()
chooseName = SystemEvents.chooseFromList(
frontWindow.tabs().map(function(t){return t.name()}),
{
withTitle: 'Safari Tabs',
emptySelectionAllowed: false
}
)
tabName = chooseName.length ? chooseName[0] : frontWindow.tabs.whose({visible: true}).at(0).name();
while (!activeApp.frontmost()){
activeApp.activate();
}
return frontWindow.tabs.whose({name: tabName}).at(0).url()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment