Package: put_in_pocket
Put in PocketSimple command line tool to add URLs to Pocket.Synopsisput_in_pocket FILE_OR_URL [FILE_OR_URL ...]DescriptionPut in Pocket is a simple command line tool to add URLs to Pocket.
It takes one or more URLs or files containing a URL as arguments and adds them to your Pocket account.If the argument is a file, the first URL found in the file is added to Pocket (subsequent URLs are ignored).
This mode of operation is primarily designed to find a URL in an email message and add it to Pocket.
See [#motivation-for-building-this-tool](Motivation for building this tool) for more details.Installationpip install --user put_in_pocketorpipx install put_in_pocketConfigurationBefore runningput_in_pocketfor the first time, you will need to obtain a consumer key from Pocket.
You can do this by creating an application athttps://getpocket.com/developer/apps/new.You will need to give your application a name and a description, and ensure thataddpermission is selected.The first time you runput_in_pocket, it will ask you to authorize it to access your Pocket account.After you get your consumer key, runput_in_pocket --authorizeand follow the instructions.You'll need to enter your consumer key then follow the link to Pocket to authorize the application.If you already have a Pocket access token, you can specify it on the command line with the--authorizeand--access-tokenoptions:put_in_pocket --authorize --consumer-key 123456-7c1d9ad1324ae57564297c142 --access-token 12345-abcd-2df4-xyz-21345(No, those are not real keys.)Once you have authorizedput_in_pocket, it will store your access token in theXDG config directoryin a file namedconfig.tomlwhich for my Mac is~/.config/put_in_pocket/config.toml.Unless you specify the--no-logoption when running,put_in_pocketwill also log to a file in theXDG data directoryin a file namedput_in_pocket.logwhich for my Mac is~/.local/share/put_in_pocket/put_in_pocket.log.Motivation for building this toolI have been a heavy Pocket user for many years and the "email to Pocket" feature is a big part of my workflow
because I often want to add URLs from devices on which I cannot install the Pocket app or browser extension.
Pocket announced in April 2023 that they werediscontinuing the email to Pocket feature.
I was disappointed by this and decided to build a tool to replace it.To use this tool to replace the email to Pocket feature, you will need to configure your email client to save the email message
to a file then runput_in_pocketon that file. I use a Mac with Apple Mail so I use theRulesfeature to save the message to a file then runput_in_pocketon that file using an AppleScript rule.To trigger the rule, I have the rule run on messages sent to my email address with a "+add" appended to the email address.
This is known asemail subaddressingand is supported by most email providers.
You could also use a dedicated email address for this purpose or use "add" in the subject line of the email, etc.Thesave_to_pocketAppleScript I use to save the email and runput_in_pocketis available inhere.-- Runs the put_in_pocket.py script to save URL found in message body to Pocket-- This script should be saved to ~/Library/Application\ Scripts/com.apple.mail/-- Then use Mail > Settings > Rules > Add Rule to create a rule to run this script when mail arrives matching your criteria-- I use "To contains myemail+add@me.com" as the rule as you can add anything after a "+" to an email address and the email-- will still be delivered-- You will need to set the variable theScripPath to the path to the script you want to run (which runs put_in_pocket.py)-- and this must be done in the 'using terms from application "Mail"' block or the script won't be able to access the variable-- The first URL in the subject line or body of the email will parsed and added to Pocket by put_in_pocket.py-- however, if the content of the email is MIME formatted, URLs will not be extractedusing terms fromapplication"Mail"onperformmailactionwithmessagestheMessagessettheScriptPathto"/Users/rhet/.local/bin/put_in_pocket.sh"repeatwiththeMessageintheMessagessettheSubjectto""settheBodyto""settheSubjecttosubjectoftheMessagesettheBodytosourceoftheMessagesetuniqueIDto(do shell script"uuidgen")-- generate a unique ID using the "uuidgen" commandsettheTempFiletoPOSIXpathof(path totemporaryitemsfolder)&"save_to_pocket_"&uniqueID&".txt"settheFileIDtoopen for accesstheTempFilewithwritepermissionwritetheSubject&" "&theBodytotheFileIDclose accesstheFileIDsettheCommandtotheScriptPath&" "&theTempFiledo shell scripttheCommandendrepeatendperformmailactionwithmessagesendusing terms fromCommand Line ToolTo see all options, runpython3 -m put_in_pocket --help:Usage: put_in_pocket.py [OPTIONS] [FILE_OR_URL]...

  Add URL or the first URL found in a text FILE to Pocket.

  FILE_OR_URL can be a URL or a path to a text file containing a URL (for
  example, an email message in .eml or .txt format)

  If FILE_OR_URL is a file and it contains multiple URLs, only the first URL
  will be added to Pocket.

  You may specify multiple FILE_OR_URL arguments.

Options:
  --version            Show the version and exit.
  --verbose            Print verbose output.
  --log / --no-log     Log to file: /Users/rhet/.local/share/put_in_pocket/put
                       _in_pocket.log.
  --dry-run            Dry run mode; don't add URL to Pocket.
  --consumer-key TEXT  Pocket API consumer key; can also be specified in
                       POCKET_CONSUMER_KEY environment variable or loaded from
                       /Users/rhet/.config/put_in_pocket/config.toml.
  --access-token TEXT  Pocket API access token; can also be specified in
                       POCKET_ACCESS_TOKEN environment variable or loaded from
                       /Users/rhet/.config/put_in_pocket/config.toml.
  --authorize          Authenticate with Pocket to get access token hen exit;
                       will store access token in
                       /Users/rhet/.config/put_in_pocket/config.toml.
  --help               Show this message and exit.LicenseMIT License, Copyright (c) 2023, Rhet TurnbullContributingBug reports and pull requests are welcome onGitHub.