Skip to content

Instantly share code, notes, and snippets.

@ftf
Created January 11, 2012 14:20
Show Gist options
  • Save ftf/1594868 to your computer and use it in GitHub Desktop.
Save ftf/1594868 to your computer and use it in GitHub Desktop.
(*
(c) 2011 Fabian Franke
Licence: Creative Commons Attribution-ShareAlike 3.0
Two variants:
with seperate flash user
1. disable flash plugin in chrome
2. create new chrome user/profile with flash enabled
3. edit theFlashChromeUser to your new flash user
without serperate flash user
1-3. nothing to do
4. enable GUI Scripting (System Prefences/Universal Access/Enable access for assistive devices
5. If you haven't installed Camino or Firefox or Opera you have to remove the marked Codeblock, otherwise the script will fail
6. assign an alfred.app global hotkey (or any other comfortable way to envoke) to this script
7. rage about without-flash-I-suck-website while browsing
8. press hotkey
9. enjoy the full legacy web experience
*)
set theFlashChromeUser to "flashy"
set browser to my GetCurrentApp()
set theURL to false
-- I wish AppleScript had a switch()case Satement
if browser is in {"Safari", "WebKit"} then
set theURL to my GetUrlFromSafari()
else if browser is in {"Chrome"} then
set theURL to my GetUrlFromChrome()
else if browser is in {"Opera"} then
set theURL to my GetUrlFromOpera()
else if browser is in {"Camino"} then
set theURL to my GetUrlFromCamino()
else if browser is in {"Firefox"} then
set theURL to my GetUrlFromFirefox()
else
return "Oops, I don't know your browser :("
end if
if theURL is not false then
my openWithFlash(theFlashChromeUser, theURL)
else
return "Can't fetch URL from your browser"
end if
on openWithFlash(theFlashChromeUser, theURL)
tell application "Google Chrome"
activate
if theFlashChromeUser is not "enterUserHere" then
tell application "System Events"
tell process "Google Chrome"
tell menu bar 1
tell menu bar item "Users"
tell menu "Users"
click menu item theFlashChromeUser
end tell
end tell
end tell
end tell
end tell
end if
delay 0.5 -- little delay if the Computer is slow due to a high load
if (URL of active tab of window 1 is not "chrome://newtab/") then
make new tab at end of tabs of window 1
end if
set URL of active tab of window 1 to theURL
end tell
end openWithFlash
on GetCurrentApp()
tell application "System Events"
get short name of first process whose frontmost is true
end tell
end GetCurrentApp
on GetUrlFromSafari()
tell application "Safari"
set theURL to URL of current tab of window 1
close current tab of window 1
end tell
return theURL
end GetUrlFromSafari
on GetUrlFromChrome()
tell application "Google Chrome"
set theURL to URL of active tab of window 1
close tab (active tab index of window 1) of window 1
end tell
return theURL
end GetUrlFromChrome
--- Camino
on GetUrlFromCamino()
tell application "Camino"
set theURL to URL of current tab of window 1
close current tab of window 1
end tell
return theURL
end GetUrlFromCamino
--- Camino
--- Opera
on GetUrlFromOpera()
tell application "Opera"
set theURL to URL of front document as string
close front document
end tell
return theURL
end GetUrlFromOpera
--- Opera
--- Firefox
on GetUrlFromFirefox()
set tmpClp to the clipboard -- don't mess with the clipboard, restore content after url is retrived
tell application "Firefox"
delay 0.5
activate
tell application "System Events"
keystroke "l" using {command down} -- select the adress bar
keystroke "c" using {command down} -- copy the contents
keystroke "w" using {command down} -- close the tab/window
end tell
end tell
delay 0.2
set theURL to the clipboard
set the clipboard to tmpClp
return theURL
end GetUrlFromFirefox
--- Firefox
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment