Skip to content

Instantly share code, notes, and snippets.

@timarnold
Last active July 7, 2019 12:37
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timarnold/4480243 to your computer and use it in GitHub Desktop.
Save timarnold/4480243 to your computer and use it in GitHub Desktop.
Inspired by Tim Bueno (http://www.timbueno.com/2012/06/27/pinboard-plus-alfred), this is an AppleScript script for Alfred to save the front-facing tab in Safari (or Chrome) to Pinboard with some tags, and get a success or failure notification from Notification Center.
-- ***********************************
-- Many thanks to Tim Bueno at http://www.timbueno.com/2012/06/27/pinboard-plus-alfred
-- for the inspiration to create this script.
-- ***********************************
on alfred_script(q)
try
-- Set this to be your Pinboard token, found here: https://pinboard.in/settings/password
set token to "MY_PINBOARD_TOKEN"
-- q is the input from Alfred after your script keyword. E.g., if "pin tag1 tag2" then
-- q is "tag1 tag2"
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 ""
-- Alternatively, use Google Chrome:
-- **********************************
-- 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
-- **********************************
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
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)
-- ******************************************************************************
-- A response from Notification Center requires the presence of
-- Display-Notification.workflow . To get this up and running, visit
-- http://hints.macworld.com/article.php?story=20120831112030251 and
-- http://www.automatedworkflows.com/2012/08/26/display-notification-center-alert-automator-action-1-0-0/
-- ******************************************************************************
if PnbdResponse contains "code=\"done\"" then
notify("Pinboard.in\\ Submission", "Successfully\\ Added", theURL)
else
notify("Pinboard.in\\ Submission", "Failed", PnbdResponse)
end if
end try
end alfred_script
on notify(title, subtitle, message)
if title as text is not "" then set title to " -D title=" & title
if subtitle as text is not "" then set subtitle to " -D subtitle=" & subtitle
if message as text is not "" then set message to " -D message=" & message
set notification to "automator" & title & subtitle & message & " ~/Dropbox/Documents/Display-Notification.workflow"
do shell script notification
end notify
--****************************************
-- 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
@timarnold
Copy link
Author

Here's a nice Pin image to use as an icon from the Noun Project: http://thenounproject.com/noun/pin/#icon-No1490

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment