Guest User

Untitled

a guest
Jun 20th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. -- AppleScript --
  2.  
  3. -- This example is meant as a simple starting point to show how to get the information in the simplest available way.
  4. -- Keep in mind that when asking for a `return` after another, only the first one will be output.
  5. -- This method is as good as its JXA counterpart.
  6.  
  7. -- Google Chrome
  8. tell application "Google Chrome" to return title of active tab of front window
  9. tell application "Google Chrome" to return URL of active tab of front window
  10. -- Google Chrome Canary
  11. tell application "Google Chrome Canary" to return title of active tab of front window
  12. tell application "Google Chrome Canary" to return URL of active tab of front window
  13. -- Chromium
  14. tell application "Chromium" to return title of active tab of front window
  15. tell application "Chromium" to return URL of active tab of front window
  16. -- Opera
  17. tell application "Opera" to return title of active tab of front window
  18. tell application "Opera" to return URL of active tab of front window
  19. -- Vivaldi
  20. tell application "Vivaldi" to return title of active tab of front window
  21. tell application "Vivaldi" to return URL of active tab of front window
  22. -- Safari
  23. tell application "Safari" to return name of front document
  24. tell application "Safari" to return URL of front document
  25. -- Safari Technology Preview
  26. tell application "Safari Technology Preview" to return name of front document
  27. tell application "Safari Technology Preview" to return URL of front document
  28. -- Webkit
  29. tell application "Webkit" to return name of front document
  30. tell application "Webkit" to return URL of front document
  31.  
  32. -- This example will return both the title and URL for the frontmost tab of the active browser, separated by a newline.
  33. -- Keep in mind that to be able to use a variable in `tell application` β€” via `using terms from` β€” we’re basically requiring that referenced browser to be available on the system.
  34. -- That means that to use this on "Google Chrome Canary" or "Chromium", "Google Chrome" needs to be installed. Same for other browsers.
  35. -- This method also does not exit with a non-zero exit status when the frontmost application is not a supported browser.
  36. -- For the aforementioned reasons, this method is inferior to its JXA counterpart.
  37.  
  38. tell application "System Events" to set frontApp to name of first process whose frontmost is true
  39.  
  40. if (frontApp = "Google Chrome") or (frontApp = "Google Chrome Canary") or (frontApp = "Chromium") or (frontApp = "Opera") or (frontApp = "Vivaldi") then
  41. using terms from application "Google Chrome"
  42. tell application frontApp to set currentTabTitle to title of active tab of front window
  43. tell application frontApp to set currentTabUrl to URL of active tab of front window
  44. end using terms from
  45. else if (frontApp = "Safari") or (frontApp = "Safari Technology Preview") or (frontApp = "Webkit") then
  46. using terms from application "Safari"
  47. tell application frontApp to set currentTabTitle to name of front document
  48. tell application frontApp to set currentTabUrl to URL of front document
  49. end using terms from
  50. else
  51. return "You need a supported browser as your frontmost app"
  52. end if
  53.  
  54. return currentTabUrl & "\n" & currentTabTitle
Add Comment
Please, Sign In to add comment