Skip to content

Instantly share code, notes, and snippets.

@tamalw
Last active December 11, 2015 03:59
Show Gist options
  • Save tamalw/4542230 to your computer and use it in GitHub Desktop.
Save tamalw/4542230 to your computer and use it in GitHub Desktop.
framework "ScriptingBridge"
unless `ps aux | grep Safari.ap[p]` == ""
safari ||= SBApplication.applicationWithBundleIdentifier("com.apple.Safari")
if ARGV.empty?
safari.windows.each do |window|
puts "Window #{window.index}:"
window.tabs.each do |tab|
puts "\t#{tab.name}"
end
end
else
safari.windows.each do |window|
window.tabs.each do |tab|
if tab.name.downcase.include? ARGV.first.downcase
safari.activate unless safari.frontmost
window.index = 1
window.currentTab = tab
end
end
end
end
else
puts "Safari is not running."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment