vitor

PinUnread — Open and manage your Pinboard “toread” bookmarks

15 posts in this topic

Before using this workflow, you need to configure it with your Pinboard account by running :configurepinunread followed by your api token and your preferred action.


zjaHg9t.png


You can get the API token of you Pinboard account by visiting https://pinboard.in/settings/password.


Your preferred action may be one of delete, archive, or keep. delete will remove the bookmark from your account, after you act (open or copy the link) on it; archive will mark the bookmark as read; keep will leave it untouched.


An example configuration would be: configurepinadd username:HSJWJK2HHSKI14QPDOIK delete


When you’re all set, call pun, and your unread bookmarks will be displayed. Press ↩ on one to open it in your default browser or ⌘+↩ to copy the link to your clipboard; the action you picked while configuring will take place in the background.


0wfAKMD.png


You may also type something after pun (don’t add a space, just type), to filter the bookmarks.


12fBicE.png

 

Download | Source

 

License

The Unlicense (Public Domain, essentially)

 

Works well with

PinAdd

Edited by vitor
jeffbyrnes likes this

Share this post


Link to post

Cool.  Unfortunately from del.icio.us days I have been in the habit of tagging stuff toread rather than using pinboard's built-in functionality.  Would it be easy to have this also search for the tag toread?  or do you have a script that could easily mark everything tagged toread as toread in Pinboard? 

Share this post


Link to post

If you use the archive action, it will not work as intended, since Pinboard does not allow (yet, although it’s taking a long time to be implemented) to simply mark a bookmark as read (meaning that for it to work, the solution is to get the information from it and then readd it without the toread option).
 
It should be easy enough for both keep and delete, though (untested, I might be forgetting something). Double-click the pun node on the workflow, and look for the big curl line that starts with curl --silent "https://feeds.pinboard.in/json/secret:${secret}/u:${user}/toread/" and change toread to t:toread, so the final result reads curl --silent "https://feeds.pinboard.in/json/secret:${secret}/u:${user}/t:toread/" (leave the rest of the line untouched). It will then search for bookmarks with the toread tag (or anything you put after t:).

The script should be possible, though, would it be a one time thing, or would you need it frequently? The difference is the former could just be a quick thing, and the latter would need some more work, to provide a good user experience.

Share this post


Link to post

Cool, thanks.  I just need it once.

 

Now that I think about it, you don’t even need a script — you can do it “manually” pretty easily. Go to https://pinboard.in/u:USERNAME/t:toread (where USERNAME is your Pinboard username) — that’ll show all your bookmarks with the toread tag. Click on edit at the top, and you’ll see a grey box appear; on select pick this page and on mark as pick unread; then on the tag line write toread and click on remove tag. It should now have removed the tag from all the bookmarks, and marked them as unread.

 

That is one crazy curl command, by the way!

 

Yep. Since the workflow needs to do a lot of stuff with the links and titles (keep them in a file so it can work within the five minute range, keep them organised in a structured way for easy retrieval, encode them to XML so they can be showed via the Script Filter, passed off to another script that’ll act on them depending on your chosen action at configuration time, doing some more encoding/decoding depending on what you picked, and more), it’d be useless to keep saving and changing a single file, when the piped commands can take care of it.

Share this post


Link to post

Hi Vítor, 

 

Thanks for this great workflow! I was wondering… is there an easy way (for a non-coder like myself) to create a duplicate of this workflow that works for starred items or any other tag? For example, could I change every instance of "unreaditems" to "starreditems" in the code and have it work in the same way for those type of bookmarks? I think I could handle a search and replace, but I'm not sure that would work and I don't want to break it. 

 

I'd appreciate any tips you might have!

 

Katie

Share this post


Link to post

I was wondering… is there an easy way (for a non-coder like myself) to create a duplicate of this workflow that works for starred items or any other tag?

Yes, that’s pretty easy to do. First, go to pinboard’s website and get the rss feed for the tag you want. Then, on the pun node (on the workflow), change the part of the code https://feeds.pinboard.in/rss/secret:${secret}/u:${user}/toread/, to whatever feed url you got on the first step, and you should be set.

Share this post


Link to post

Yes, that’s pretty easy to do. First, go to pinboard’s website and get the rss feed for the tag you want. Then, on the pun node (on the workflow), change the part of the code https://feeds.pinboard.in/rss/secret:${secret}/u:${user}/toread/, to whatever feed url you got on the first step, and you should be set.

 

 

Sorry, Vítor, I must have inadvertently broken something.

 

I wanted to keep the original functionality you made so I tried to copy and paste the same code into a new keyword "node" and change the url you told me about in the new keyword node. I linked the new node to both of the script action nodes that are linked to the pun node. Everything seemed to break after that…now I can't get it to do anything. I re-downloaded your workflow and it replaced the mess I made, then re-configured. I even reset my api token thing on Pinboard, and re-configured that. (I'm sure the new token works because I had to input it into PinAdd). 

 

But after all that, the pun keyword in Alfred just does a default web search. I've tried re-downloading the workflow several times and restarting my computer…not really sure what else to try. Is it possible that deleting the workflow and re-installing doesn't actually delete everything?

Share this post


Link to post

Sorry, Vítor, I must have inadvertently broken something.

 

I wanted to keep the original functionality you made so I tried to copy and paste the same code into a new keyword "node" and change the url you told me about in the new keyword node. I linked the new node to both of the script action nodes that are linked to the pun node. Everything seemed to break after that…now I can't get it to do anything. I re-downloaded your workflow and it replaced the mess I made, then re-configured. I even reset my api token thing on Pinboard, and re-configured that. (I'm sure the new token works because I had to input it into PinAdd). 

 

But after all that, the pun keyword in Alfred just does a default web search. I've tried re-downloading the workflow several times and restarting my computer…not really sure what else to try. Is it possible that deleting the workflow and re-installing doesn't actually delete everything?

Ah, yes, I think I know what went wrong.

If you want to have more than one node, it becomes a bit trickier, unfortunately. I’ll first tell you how to fix it, and then I’ll explain how the workflow works, so you have a sense as to why everything is breaking after that change.

How to fix it

You need to open the workflow’s directory, and for each new node you want, you have to make a new copy of the file pinunread (names do not matter, but you should name them something that explains them, like pinunread_starred).

Now you’ll basically replicate the nodes inside the workflow (with the exception of the configuration one) as many times as you need, meaning that you won’t just copy pun and connect it to the other existing two nodes, you have to copy those as well. Let’s go through the process of adding the starred items idea (so we have something real to work with).

  • Go inside the workflow’s directory and copy pinunread. Name the copy pinunread_starred.
  • Make a new Script Filter and two Run Script nodes (or one, if you only need the open link functionality, and not the one to copy links to clipboard).
  • Inside the Script Filter node, change the url as before.
  • Now, in addition, change the line unreaditems="$(getDataDir)/unreaditems.txt" to use another file — change only the “unreaditems.txt” part, so you end up with something like unreaditems="$(getDataDir)/starreditems.txt".
  • Now go into each of the new nodes and paste the code that you have in the existing ones, but change pinunread to pinunread_starred (so these new nodes will call the file you created previously).
  • Lastly, go into your pinunread_starred file (open with a standard editor, like TextEdit, just be sure so have it save as a plain text file, and remove any extension, can’t stress this enough), and change, right at the top, the unreaditems="$(getDataDir)/unreaditems.txt" to be the same of what you picked earlier.

Now the part you can skip, if you get the previous working and do not really care for how the workflow’s internals work.

How it works

You are correct, deleting the workflow does not delete everything — like other OS X apps, Alfred has some directories inside your Library directory on your home (it’s hidden by default on OS X Lion and newer). Inside these are other directories for workflows to keep settings. This is useful since if you sync your settings with Dropbox, not only do I not need to store your sensitive information (Pinboard’s API token) there (which means that if Dropbox is compromised, your info won’t be), it allows you to have different settings per computer. To delete everything, open a terminal and run rm -r ~/Library/Application\ Support/Alfred\ 2/Workflow\ Data/com.vitorgalvao.alfred.pinunread.

If you read the section “Technical details” on the first post of this thread, I say

 

The workflow will download your unread bookmarks every time you call it, unless you’ve done it in the last five minutes. This is not only to prevent constant calls to Pinboard’s servers, but also to make it speedier if you want to open multiple bookmarks in succession.

The way it was implemented, though, lead to a small annoyance (yes, it also annoyed me, but it hadn’t yet been fixed; it is now, please download the latest version). Here’s what it did — you called pun and it checked to see if the file where it saves the links existed, and if it was accessed less than five minutes ago; if both of these were true, it’d just reread the file, else it’d fetch the required info again. This made it so that if you called pun and interrupted it while downloading, the file would be created and it would have been touched, it’d simply be empty (because it wasn’t allowed to finish); the way it works now, it also checks if it is empty.

With the addition of new Script Filter nodes writing to the same file, it was overwriting it and confusing it all the time, which is why you need to duplicate them, as outlined previously.

Final notes

Could this be made easier? Yes, definitely. Unfortunately, the workflow was made with a very specific purpose, to do one thing well, which is why this changes will take a bit of effort. However, different people have different needs, so I hope the instructions above work for you. If not, tell me where you get stuck.

Share this post


Link to post

Ah, yes, I think I know what went wrong.

If you want to have more than one node, it becomes a bit trickier, unfortunately. I’ll first tell you how to fix it, and then I’ll explain how the workflow works, so you have a sense as to why everything is breaking after that change.

 

 

Wow, Vítor, I don't even know what to say except thank you so much: For your detailed explanation of how to fix the problem and of how the workflow actually works, for your effort in writing it all up so thoughtfully, and for taking the time to help me with something that you weren't necessarily interested in doing yourself.

 

I followed every step exactly and now I can search both unread and starred bookmarks. I've also gained a deeper understanding of how it works so I think I could modify it if I ever needed to search another section of Pinboard. Thank you!! I am so grateful. I am also really sorry to inconvenience you just for my own specific wants… but given the nature of the changes and that I don't think I could do it myself… I'm just so appreciative of your help!

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now