Skip to content

Instantly share code, notes, and snippets.

@thomasjbradley
Last active September 17, 2015 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasjbradley/702c68d097fa56ab083d to your computer and use it in GitHub Desktop.
Save thomasjbradley/702c68d097fa56ab083d to your computer and use it in GitHub Desktop.
(*
Copyright spamwax; https://github.com/spamwax/alfred-pinboard
*)
on appIsRunning(appName)
tell application "System Events" to (name of processes) contains appName
end appIsRunning
on run
set theApplication to (name of (info for (path to frontmost application)))
set theText to ""
set theURL to ""
set theBrowser to ""
if theApplication is "Google Chrome.app" and appIsRunning("Google Chrome") then
set theResult to run script "tell application id \"com.google.chrome\"
using terms from application \"Google Chrome\"
set theText to title of active tab of first window
set theURL to get URL of active tab of first window
return {theURL, theText}
end using terms from
end tell"
set theURL to item 1 of theResult
set theText to item 2 of theResult
set theBrowser to "Google Chrome.app"
else if theApplication is "Safari.app" and appIsRunning("Safari") then
set theResult to run script "tell application id \"com.apple.safari\"
using terms from application \"Safari\"
set theTab to front document
set theText to name of theTab
set theURL to URL of theTab
return {theURL, theText}
end using terms from
end tell"
set theURL to item 1 of theResult
set theText to item 2 of theResult
set theBrowser to "Safari.app"
else if theApplication is "Chromium.app" and appIsRunning("Chromium") then
set theResult to run script "tell application \"Chromium\"
set theURL to URL of active tab of first window
set theText to title of active tab of first window
return {theURL, theText}
end tell"
set theURL to item 1 of theResult
set theText to item 2 of theResult
set theBrowser to "Chromium.app"
else if theApplication is "Firefox.app" and appIsRunning("Firefox") then
set theResult to run script "tell application id \"org.mozilla.firefox\"
activate
set w to item 1 of window 1
set theText to name of w
end tell
tell application \"System Events\"
set myApp to name of first application process whose frontmost is true
if myApp is \"Firefox\" then
tell application \"System Events\"
keystroke \"l\" using command down
delay 0.5
keystroke \"c\" using command down
end tell
delay 0.5
end if
delay 0.5
end tell
set theURL to get the clipboard
return {theURL, theText}"
set theURL to item 1 of theResult
set theText to item 2 of theResult
set theBrowser to "Firefox.app"
end if
return {theURL, theText, theBrowser}
end run
<?php
exec('osascript -s so ./get-current-url.applescript', $raw);
$details = explode('", "', preg_replace(['/^\{"/', '/"\}$/'], '', $raw[0]));
if (!preg_match('/github/', $details[0])) exit;
$url = preg_replace('/https?\:\/\//', '', $details[0]);
if (preg_match('/github\.io/', $url)) {
preg_match('/(.+)\.github/', $url, $usernameMatches);
preg_match('/\.github\.io\/([^\/]+)/', $url, $repoMatches);
$finalUrl = "https://github.com/$usernameMatches[1]/$repoMatches[1]";
} else {
preg_match('/github.com\/([^\/]+)/', $url, $usernameMatches);
preg_match("/github\.com\/$usernameMatches[1]\/([^\/]+)/", $url, $repoMatches);
$finalUrl = "http://$usernameMatches[1].github.io/$repoMatches[1]/";
}
exec("open -a '$details[2]' '$finalUrl'");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment