Pocket integration

Here’s my script for Pocket integration — doesn’t appear to be a way to get a better title unfortunately.

Get Address script

tell application "System Events"
	tell process "Pocket"
		if enabled of menu item "Copy Item" of menu 1 of menu bar item "Item" of menu bar 1 then
			-- Item selected
			click menu item "Copy Item" of menu 1 of menu bar item "Item" of menu bar 1
			delay 0.5
			set theURL to the clipboard
			set theTitle to "Pocket article: " & theURL
			return "[" & theTitle & "](" & theURL & ")"
		end if
		-- else item not selected
	end tell
end tell
2 Likes

thank you! I am also a Pocket subscriber/user, though I don’t use the app version anymore. (I’d rather have the full power of a web browser, with its extensions and services. E.g., I use it in combination with Pinboard, adding Pinboard notes to pages. But that’s just me.)

Note to readers: the URLs returned by the Pocket app are web links, so they will take you to a web browser. the advantage is that any Hook link you’ve made in the context of a browser is shown in Pocket, and vice versa. In my case that is the desired behavior.

There might be a clever way to open items in Pocket itself based on its library data —I haven’t checked yet.

Also: when you archive a web page on Pocket, it of course gets its own URL on https://app.getpocket.com/read/3019674262 . Pocket normally exposes the original URL via a “View Original” link at the top (but some of its featured articles don’t). I’ve long wanted to ‘unify’ the original web URL with the pocket URL. That is an instance of a more general and interesting problem that interests me a lot in relation to Hook. The idea is that anything linked to the https://app.getpocket.com URL should automatically be treated as linked to the original URL, and vice versa. (another example: a DEVONthink think file has a DEVONthink:// url, but also a transient file:// URL and a hook://URL). We’ve got some thoughts on this and are open to thoughts/opinions. We haven’t had time to address that super generally, but as we grow and resources permit, it’s something I definitely want to do.

Anyway, we’ll add the basic script in English, French and German. If anyone wants to contribute other languages, please do. And that goes for any UI scripted app in Hook. We might organize that page in a table later, and should have one specific page per app – as a focal point.

1 Like

Another note for others who might try this: the title is based on the URL.
We have written a script for Apple News that prompts the user for a title. That could be done in the case of Pocket too. (And I wouldn’t be surprised if we could find the Pocket title data in its library folder, but haven’t checked yet.) Once we publish the Apple News script, forum members might want to adapt it or suggest tweaks.

Also: when we introduce a function to rename Hook’s bookmarks (that back links), prompting for a title will be less relevant, particularly for Pocket given that the URL gets you in the ballpark.

Also: in case of Pocket a call to the website could in principle be made in the script to retrieve the title associated with the URL (if not firewalled). However, Hook doesn’t do arbitrary web calls (just update check / license)-- it could technically, but the app and its built-in scripts don’t as we would need to add preferences and checks around that.

further note… Hook should update the title of arbitrary bookmarks when Hook is invoked on them (feature in progress). That should mean that the title you will see for a Pocket bookmark will be updated after you invoke Hook on the same URL in a web browser. (Hook gets the title directly from the web browser).

NB: titles of hook://file bookmarks are already auto-updated, even without revisiting the file via Hook.

Here’s a better version that does provide the page title. Is this what you want to avoid in official code?

Important! See following comment. This code makes an internet call to fetch the title.

tell application "System Events"
	tell process "Pocket"
		if enabled of menu item "Copy Item" of menu 1 of menu bar item "Item" of menu bar 1 then
			-- Item selected
			click menu item "Copy Item" of menu 1 of menu bar item "Item" of menu bar 1
			delay 0.5
			set theURL to the clipboard

			set theTitle to do shell script "curl " & quoted form of theURL & " | grep -o '<title>.*</title>' | sed 's/<title>//g' | sed 's;</title>;;g'"

			return "[" & theTitle & "](" & theURL & ")"
		end if
		-- else item not selected
	end tell
end tell

Thanks, Steve.

Yah, it would call for some documentation and a preference. Anyone using the script above needs to know that the script makes a call to the website to get the title associated with that URL. So we won’t build that part in yet. (I will use it though.)

1 Like

I’ve edited above to add this warning.

1 Like