Last active
April 3, 2017 04:19
-
-
Save rjames86/6f847988f829387832e892731c0ce614 to your computer and use it in GitHub Desktop.
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 = 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