+Mineral2 Posted June 18, 2014 Share Posted June 18, 2014 Warning: This post is for Unix-based OS users (Mac, Linux, etc.) who like to use their computers beyond the point-and-click interface. As a computer nerd, I like to find solutions that automize repetitive tasks. Therefore, I've written a little bash script that unzips pocket query files directly to the gps (or sd card), deletes the associated waypoints file (optional), and corrects the mystery/unknown cache icons (latest addition). I thought I'd share my program in the hopes that it will help some of you out, and in hopes that some of you can help me optimize the script and make it more universal. Challenge #1: identifying pocket query files. My most commonly used pocket queries begin with the number 1, but it seems that newer queries now begin with the number 2. Therefore, to distinguish PQ gpx files from non PQ files, I'd like to be able to identify all files that begin with a number. You'll see where this applies in the code below. The program: #!/bin/bash #This script will unzip pocket queries and place the gpx files on the SD card of the gps. cd ~/Desktop/export/GPX/ echo "Do you wish to clear all Pocket Query files?" echo "Type yes or no." read rem if [ "$rem" = "yes" ]; then rm /Volumes/GPS\ SD\ CARD/Garmin/gpx/1*.gpx fi for i in *.zip do unzip -o $i -d /Volumes/GPS\ SD\ CARD/Garmin/gpx done rm *.zip echo Do you want to keep the waypoint files? echo Type \"yes\" or \"no\". read wpt if [ "$wpt" = "no" ]; then echo "Removing waypoints files." rm /Volumes/GPS\ SD\ CARD/Garmin/gpx/*wpts.gpx fi echo Do you need to correct Mystery caches? echo Type \"yes\" or \"no\". read myst if [ "$myst" = "yes"]; then cd /Volumes/GPS\ SD\ CARD/Garmin/gpx/ for file in 1*.gpx do echo fixing $file sed -i.bak s/Mystery\ Cache/Unknown\ Cache/g $file done rm *.bak fi echo "Done!" exit Quote Link to comment
+MartyBartfast Posted June 18, 2014 Share Posted June 18, 2014 (edited) Did you know that at the end of the PQ creation screen there's a tick box which says: Include Pocket Query name in download file name so I named all my scheduled Pocket Queries as "PQ 01", "PQ 02",... etc, then the .zip files are named randomnumber_PQ01.zip etc, and the gpx files within the zip are named randomnumber_PQ01.gpx and randomnumber_PQ01-wpts.gpx. (note if you have spaces in the Pocket Query name then the spaces will be removed from the filenames) So if you name all your Pocket Queries with something identifiable and tick that box, identifying the pocket query files becomes easy. Edit to add (in case there are any pedants watching), yes I know it's not actually a random number, but for the purposes of this exercise it may as well be. Edited June 18, 2014 by MartyBartfast Quote Link to comment
+Mineral2 Posted June 18, 2014 Author Share Posted June 18, 2014 I've thought about doing that. I've got a fair number of pocket queries, but it wouldn't be hard to rename them. Also... one thing I forgot to mention, but in order for the sed program to work properly to fix the mystery-unknown cache issue, the file names can't have any spaces or special characters in them. Quote Link to comment
+MartyBartfast Posted June 18, 2014 Share Posted June 18, 2014 The can if you quote the filename, so sed -i.bak s/Mystery\ Cache/Unknown\ Cache/g $file becomes sed -i.bak s/Mystery\ Cache/Unknown\ Cache/g "$file" I would also quote the sed string, to avoid escaping the spaces as I think it make it more readable, but that's just a matter of preference: sed -i.bak "s/Mystery Cache/Unknown Cache/g" "$file" Quote Link to comment
+Mineral2 Posted June 19, 2014 Author Share Posted June 19, 2014 Thank you. I also found the answer to my original problem: display only gpx files that begin with a number: ls [0-9]*.gpx I've updated my script with this and MartyBartfast's sugestion so that it should be universal to anybody's PQ naming scheme. Of course, you'll have to modify the directories to match your GPS. #!/bin/bash #This script will unzip pocket queries and place the gpx files on the SD card of the gps. #cd ~/Desktop/export/GPX/ echo "Do you wish to clear all Pocket Query files?" echo "Type yes or no." read rem if [ "$rem" = "yes" ]; then rm /Volumes/GPS\ SD\ CARD/Garmin/gpx/[0-9]*.gpx fi for i in *.zip do unzip -o $i -d /Volumes/GPS\ SD\ CARD/Garmin/gpx done rm *.zip echo Do you want to keep the waypoint files? echo Type \"yes\" or \"no\". read wpt if [ "$wpt" = "no" ]; then echo "Removing waypoints files." rm /Volumes/GPS\ SD\ CARD/Garmin/gpx/*wpts.gpx fi echo Do you need to correct Mystery caches? echo Type \"yes\" or \"no\". read myst if [ "$myst" = "yes" ]; then cd /Volumes/GPS\ SD\ CARD/Garmin/GPX for file in [0-9]*.gpx do echo fixing $file sed -i.bak "s/Mystery Cache/Unknown Cache/g" "$file" done rm *.bak fi echo "Done!" exit Quote Link to comment
+Mineral2 Posted August 16, 2016 Author Share Posted August 16, 2016 This is the latest iteration that I've been using. Includes some parallel processing to load multiple files on your device at once, because Garmin hasn't kept up with modern USB port speeds and a full PQ takes "a while" to transfer. #!/bin/bash #This script will unzip pocket queries and place the gpx files on the SD card of the gps. #cd ~/Desktop/export/GPX/ echo "Do you wish to delete all Pocket Query files currently on the device?" echo \"yes\" or \"no\" read rem echo Do you want to keep the waypoint files? echo \"yes\" or \"no\" read wpt echo Do you wish to delete the original .zip files? echo \"yes\" or \"no\" read delzip if [ "$rem" = "yes" ]; then echo Removing previously installed PQ files. rm /Volumes/GPS\ SD\ CARD/Garmin/gpx/[0-9]*.gpx fi for i in *.zip do unzip -o $i -d /Volumes/GPS\ SD\ CARD/Garmin/gpx & done wait if [ "$delzip" = "yes" ] then echo Deleting downloaded .zip files. rm *.zip fi if [ "$wpt" = "no" ]; then echo "Removing waypoints files." rm /Volumes/GPS\ SD\ CARD/Garmin/gpx/*wpts.gpx fi echo "Done!" exit Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.