Step 4 - Automating the process
Having the production of custom GPX automated is really nice. There are two different facets that need to be covered.
Savings Pocket Queries from email
I have been able to add a rule to Mail on the Mac that saves any attachments - e.g. the zip files - from incoming pocket queries. By checking the subject of the email for [GEO] Pocket Query:, I can then set an Applescript to run that saves the attachment to my PQs folder and then moves the email to the trash. Without me ever having to see or delete them!
on perform_mail_action(theData)
tell application "Mail"
set theSelectedMessages to |SelectedMessages| of theData
set theRule to |Rule| of theData
set theOutputFolder to "Frost:Users:gpt:Documents:Geocaching:PQs:"
repeat with a from 1 to count theSelectedMessages
set theMessage to item a of theSelectedMessages
set theAttachments to every attachment of content of theMessage
repeat with b from 1 to count theAttachments
set theAttachment to item b of theAttachments
set theAttachmentName to name of theAttachment
try
set theSavePath to theOutputFolder & theAttachmentName
tell application "Finder"
if exists theSavePath then
delete theSavePath
end if
end tell
save theAttachment in theSavePath
end try
end repeat
try
set mailbox of theMessage to mailbox "Trash"
end try
end repeat
end tell
end perform_mail_action
Build it on a regular basis
The ultimate step, is to run the buildit script on a quasi-regular basis. Initially I was going to have the script run after the arrival of a new pocket query, but sometimes they come down in twos so I wanted to avoid being run twice. Instead I opted for the ever useful crontab that most unixes provide. Off I hopped into /etc/crontab and added the following line.
00 6-12,16,23 * * * gpt /Users/gpt/Documents/Geocaching/PQs/buildit.sh
To those that haven't dabble in the seemingly arcane unix commands - this builds my pocket queries every day; hourly from 0600-1200, again at 1600 in case I go out after work, and finally late in the evening in case I'm up early the next day to go caching.
It has taken a few hours learning GPSBabel to get this set up, but I am looking forward to the time it is going to save me in the future. I'd be interested if any other Mac or Unix folks use a similar approach. Alas it is not the easiest to do on Windows - but hey, you've got GSAK so stop complaining ;)
Source files
Below I have provided copies of these files in case anyone else wants to play, tinker or improve them. Most of them will download best if you right-click and save-them-as...
