So lately I've been getting into creating my own scripts for GeekTool and one thing I'm constantly doing is tracking packages. I hate having to open up a browser and track the package that way. I wanted to make a script that could be dynamically ran with multiple tracking numbers at once in GeekTool. I've made this script that can be used with a tracking number to display the tracking history of a UPS shipment.
Save the above to a .sh file and store it somewhere you can get to. You may have to chmod it to make it executable depending on your setup. Then, in GeekTool, create a new shell geeklet and just call your shell script with a tracking number and description like this:
The tracking number above is bogus, but the output of a real tracking number will look like this in GeekTool or any Terminal:
I'm sure this isn't the cleanest script ever. I know the line with the seds got crazy and I'm sure you could condense it if you wanted but this works so it works for me haha. Feel free to suggest any modifications. This is my first real stab at this sort of thing so I'm not claiming to be perfect. Hopefully this will make someones life easier like it does mine. Enjoy.
-cs
Code:
#!/bin/bash
#ups tracking url with $1 passed from shell
TRACKSITE="http://wwwapps.ups.com/WebTracking/processInputRequest?track.x=0&track.y=0&InquiryNumber1="$1
#store html source to variable
T=$(curl --silent $TRACKSITE)
#parse out unnecessary html and leave relevant text only
S=$(echo "$T" | sed -n '/<!-- START: Standard 1Z Tracking Package Progress Box -->/,/<!-- END: Standard 1Z Tracking Package Progress Box -->/p' | sed -n '/<table/,/<\/table/p' | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/ /g' | tr -d '[:blank:]' | sed 's/<\/tr>/\'$'\n/g' | sed 's/<tdclass=\"nowrap\"><\/td>/\[N\/A\]/g' | sed 's/<[^>]*>/ /g' | sed 's/,UnitedStates/,USA/g' | sed 's/Scan/_Scan/g' | sed 's/\.//g'| column -t)
#echo formatted text with $1 and $2 passed from shell
echo -e "DESCRIPTION: $2\nTRACKING NUMBER: $1\n$S"
Save the above to a .sh file and store it somewhere you can get to. You may have to chmod it to make it executable depending on your setup. Then, in GeekTool, create a new shell geeklet and just call your shell script with a tracking number and description like this:
Code:
/path/to/your/script/geeklet_ups_tracker.sh 1ZR441800196847996 MY_SHIPMENT_NAME
The tracking number above is bogus, but the output of a real tracking number will look like this in GeekTool or any Terminal:
Code:
DESCRIPTION: MY_SHIPMENT_NAME
TRACKING NUMBER: 1ZR441800196847996
Location Date LocalTime Activity
LittleRock,AR,USA 02/25/2014 7:09AM OutForDelivery
LittleRock,AR,USA 02/24/2014 7:57PM Arrival_Scan
OklahomaCity,OK,USA 02/24/2014 1:30PM Departure_Scan
OklahomaCity,OK,USA 02/21/2014 10:51PM Arrival_Scan
Salina,KS,USA 02/21/2014 6:27PM Departure_Scan
[N/A] 02/21/2014 4:56PM Arrival_Scan
CommerceCity,CO,USA 02/21/2014 5:55AM Departure_Scan
CommerceCity,CO,USA 02/20/2014 3:40PM Arrival_Scan
SaltLakeCity,UT,USA 02/20/2014 6:26AM Departure_Scan
[N/A] 02/20/2014 1:11AM Origin_Scan
UnitedStates 02/19/2014 1:00AM OrderProcessed:ReadyforUPS
I'm sure this isn't the cleanest script ever. I know the line with the seds got crazy and I'm sure you could condense it if you wanted but this works so it works for me haha. Feel free to suggest any modifications. This is my first real stab at this sort of thing so I'm not claiming to be perfect. Hopefully this will make someones life easier like it does mine. Enjoy.
-cs