Guest User

Untitled

a guest
May 16th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. function switchBrowser()
  2. local current = hs.application.frontmostApplication()
  3. local bool,URL
  4.  
  5. if (current:name() == "Google Chrome") then
  6. bool,URL = hs.osascript.applescript('tell application "Google Chrome" to get URL of active tab of window 0')
  7. if bool then
  8. if (string.match(URL,'chrome://')) then
  9. hs.alert('not a valid link')
  10. else
  11. hs.execute('open -a Safari "' .. URL .. '"')
  12. end
  13. else
  14. hs.alert('error getting URL')
  15. end
  16. elseif (current:name() == "Safari") then
  17. bool,URL = hs.osascript.applescript('tell application "Safari" to get URL of document of window 0')
  18. if bool then
  19. if (string.match(URL,'favorites://')) then
  20. hs.alert('not a valid link')
  21. else
  22. hs.execute('open -a "Google Chrome" "' .. URL .. '"')
  23. end
  24. else
  25. hs.alert('error getting URL')
  26. end
  27. else
  28. hs.alert('no focused browser')
  29. end
  30.  
  31. end
Add Comment
Please, Sign In to add comment