KM Macro to Save Safari's current top window's current tab to Pinboard

I do a lot of browsing in Private mode and I often want to save the top page to Pinboard without re-opening a new non-private window or logging into Pinboard from a private window. So I wrote a Keyboard Maestro Macro to do just that.

To use this you need to set your Pinboard API token. This can be found in Pinboard.in > Settings > Password

It’s in large blue letters on the screen and is your username:<longHexString>

Here is a Dropbox Link to the source code.

There are lots of opportunities to expand on this, but I started simple.

Share & Enjoy!

2 Likes

If you’d like, you can go to File | Export Macros… and export the macro to post here.
Assuming this Discourse will let you upload the .kmmacros file, if not, you might have to zip it.

1 Like

Added a Dropbox link to the original post.

1 Like

File | Edit | Copy As has copy as Text which is great for a forum too!

i.e.
Save top Safari Window's tab to Pinboard
Triggered by any of the following:
The Hot Key ⌃⌥⇧⌘1 is pressed
Will execute the following actions:
Set Variable “localPinboardAccessToken” to Text
Note: Set this to your Pinboard API Token. The format is:

Username:ABCD23E78A0D68E50FF1F

And can be found at Pinboard.in > Settings > Password
Execute AppleScript
tell application "Safari"
    
    set windowNumber to 1
    set myTabs to first tab of window windowNumber
    set tabNumber to 0
    set aTab to current tab of window windowNumber
    
    set tabTitle to name of aTab
    set tabURL to URL of aTab
    
    tell application "Keyboard Maestro Engine"
        setvariable "lastSafariTabURL" to tabURL
        setvariable "lastSafariTabTitle" to tabTitle
    end tell
    
end tell

Filter Variable “lastSafariTabURL” with Percent Encode for URL
Store result to Variable “localEncodedURL”.
Filter Variable “lastSafariTabTitle” with Percent Encode for URL
Store result to Variable “localEncodedTitle”.
Display Text Large
%Variable%lastSafariTabTitle%

%Variable%localEncodedTitle%

%Variable%lastSafariTabURL%

%Variable% localEncodedURL%
Execute Shell Script
curl "https://api.pinboard.in/v1/posts/add?shared=yes&format=json&auth_token=$KMVAR_localPinboardAccessToken&description=$KMVAR_localEncodedTitle&toread=no&url=$KMVAR_localEncodedURL&replace=yes"
Display trimmed results without errors briefly.
Stop macro and notify on failure.
1 Like

Very nice! I can definitely see this coming in handy.

You might want to also post it to https://forum.keyboardmaestro.com

Done! That does seem to be a better place to post Keyboard Maestro Macros since once can upload the kmmacros file directly.

I’ve got a couple macro sets (one for relative dates, and one for state abbreviations) that I’ll probably post. Should I cross post here or just post the description with a link over to the KM forum?

1 Like

That’s cool, but it loses some details, like the debug code that I have disabled and the highlighted step where the user needs to put in their Pinboard API token.

I cross posted over at the Keyboard Maestro forums with an updated image and the kmmacros file with the source code.

1 Like