Abstract
This article provides a guide for creating an AppleScript that registers
as the default handler for the feed URI scheme on a local machine. The
script forwards all URIs to a remote instance and registers it into
rss2email. It also contains some useful notes about running
rss2email on remote host.
Create and register proxy application
The first section of this article describes the process of creating an
application that serves as a proxy to add feeds to a remote rss2email
on a specific host.
The integration is achieved using AppleScript. The first step of integration is creating a new script with the following content:
property rss2emailHost : "some.host.net"
property sshAuthSocket : ""
on open location feedUri
try
if {feedUri does not start with "feed:"} then
display alert "Unexpected feed URI: " & feedUri
return
end if
set feedUri to (items 6 thru -1 of feedUri) as string
if {feedUri is ""} then
display alert "Empty feed URI"
return
end if
set feedQueryQuestion to "Please Enter Feed name for: " & feedUri
set feedQueryTitle to "Enter name for new RSS feed"
set feedQueryButtons to {"Reject", "Save", "Save via Web Archive"}
set feedQuery to display dialog feedQueryQuestion default answer "" buttons feedQueryButtons with title feedQueryTitle default button 1
set clickedButton to the button returned of the feedQuery
set feedName to text returned of the feedQuery
if ({feedName is ""} or {clickedButton is "Reject"}) then
return
end if
if {clickedButton is "Save via Web Archive"} then
set feedUri to "https://web.archive.org/web/" & feedUri
end if
set sshCmd to "ssh " & rss2emailHost & " r2e add " & feedName & " " & feedUri & " 2>&1"
if {sshAuthSocket is not ""} then
set sshCmd to "env SSH_AUTH_SOCK=" & sshAuthSocket & " " & sshCmd
end if
set sshOutput to do shell script sshCmd
if {sshOutput is not ""} then
display alert sshOutput
end if
on error errMsg
display alert errMsg
end try
end open location
replace some.host.net with the name of the host that was used.
Note that the script supports the use of a custom ssh-agent socket,
which can be configured via the sshAuthSocket parameter. This
parameter expects the full path to the socket or an empty string.
This script should be saved as application into ~/Application folder.
Once saved as an application, the URI handler should be added by adding
code below into Contents/Info.plist inside the application after the
last CFBundle key-value pair:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>RSS feed</string>
<key>CFBundleURLSchemes</key>
<array>
<string>feed</string>
</array>
</dict>
</array>
When the application is launched for the first time, this script gets
registered as an available handler for the feed URI scheme. The
application can now be configured as the default handler for this scheme
through
SwiftDefaultApps or a
similar application, or by manually editing
~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist.
Notes on Remote Settings
The script provides two buttons: Save and Save via Web Archive. The
latter uses Web Archive as a source of feed,
which can be useful when the remote host blocks your server for some
reason.
However, this approach may introduce a delay that depends on the
crawling cycle of the Web Archive. The crawling cycle can be controlled
via the line below in crontab. Each call
suggests, but does not enforce, crawling of the provided URL.1
~ ~ * * * r2e opmlexport | xq -r '.opml.body.outline[]."@xmlUrl"' | grep 'https:\/\/web.archive.org\/web\/' | sed -e 's/\/web\//\/save\//' | xargs curl --fail --silent -o /dev/null || echo Update Web Archive for rss2email fails