Last active
August 29, 2015 14:25
-
-
Save thomasjbradley/b7ac09a3bbf62224b2b0 to your computer and use it in GitHub Desktop.
An Alfred workflow for quick pinning to Pinboard.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
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 "" | |
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 | |
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 | |
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 | |
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 | |
end if | |
return {theURL, theText} | |
end run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
exec('osascript -s so ./get-current-url.applescript', $raw); | |
$details = explode('", "', preg_replace(['/^\{"/', '/"\}$/'], '', $raw[0])); | |
// For removing extra things in the title that I dislike | |
$titleJunk = [ | |
' - Vimperator' => '' | |
]; | |
$qs = http_build_query([ | |
'auth_token' => 'YOUR_API_KEY_HERE', | |
'url' => $details[0], | |
'description' => str_replace(array_keys($titleJunk), $titleJunk, $details[1]), | |
'shared' => 'no', | |
'toread' => 'yes' | |
]); | |
$resp = file_get_contents('https://api.pinboard.in/v1/posts/add?' . $qs); | |
if (strpos($resp, '<result code="done" />') !== false) { | |
echo 'Bookmark successfully saved.'; | |
} else { | |
echo 'Bookmark save failed.'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment