Last active
December 3, 2024 11:22
-
-
Save rretsiem/4608700 to your computer and use it in GitHub Desktop.
Sends the current active Safari Tab to Pinboard with Tags via the Query from Alfread and prints the result via Growl.
Originally written by Tim Bueno: http://www.timbueno.com/2012/06/27/pinboard-plus-alfred
This file contains hidden or 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
on alfred_script(q) | |
try | |
set token to "<API TOKEN can be found on pinboard.in/settings/password>" | |
set inputt to q as text | |
set tmp to splitString(inputt as text, " ") | |
set AppleScript's text item delimiters to "+" | |
set q to tmp as string | |
set AppleScript's text item delimiters to "" | |
tell application "Safari" | |
set theURL to URL of current tab of window 1 | |
set theDesc to name of current tab of window 1 | |
end tell | |
-- Google Chrome also works, comment Safari out, only one will work: | |
-- ********************************** | |
-- tell application "Google Chrome" | |
-- set theURL to URL of active tab of first window | |
-- set theDesc to title of active tab of first window | |
-- end tell | |
-- ********************************** | |
set tmp to splitString(theDesc as text, " ") | |
set AppleScript's text item delimiters to "+" | |
set theDesc to tmp as string | |
set AppleScript's text item delimiters to space | |
set growlDesc to tmp as string | |
set AppleScript's text item delimiters to "" | |
set shellScript to ("curl --url \"https://api.pinboard.in/v1/posts/add?url=" & theURL & "&description=" & theDesc & "&tags=" & q & "&auth_token=" & token & "\"") | |
set PnbdResponse to (do shell script shellScript) | |
if PnbdResponse contains "code=\"done\"" then | |
tell application "Growl" to notify with name "Extension Output" title "Sent to Pinboard" description "\"" & growlDesc & "\" has been saved!" application name "Alfred" icon of application "Alfred" | |
else | |
tell application "Growl" to notify with name "Extension Output" title "Failed! - Sent to Pinboard" description "There was a problem. Check your username and password." application name "Alfred" icon of application "Alfred" | |
end if | |
end try | |
end alfred_script | |
--**************************************** | |
-- Split String | |
--(thanks to Geert JM Vanderkelen for this code! | |
--http://geert.vanderkelen.org/post/241/) | |
--**************************************** | |
to splitString(aString, delimiter) | |
set retVal to {} | |
set prevDelimiter to AppleScript's text item delimiters | |
log delimiter | |
set AppleScript's text item delimiters to {delimiter} | |
set retVal to every text item of aString | |
set AppleScript's text item delimiters to prevDelimiter | |
return retVal | |
end splitString |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment