set trackNum to <a tracking number>
set fedexURL to "http://www.fedex.com/Tracking?language=english&cntry_code=us&tracknumbers="
set whoSigned to do shell script "curl -A \"Mozilla/4.0\" -s " & fedexURL & trackNum (*& " | awk '/Signed for by / {print $4}' | cut -f 1 -d '<' "*)
Here’s my problem:
Applescript stops responding everytime I run this command. It doesn’t even work using just the fedexURL Url (so if you can’t think of a tracking number to put in there, curl isn’t even opening that page). Yet I am able to get this to work going to just “http://www.fedex.com”.
set whoSigned to do shell script "curl -A \"Mozilla/4.0\" -s " & quoted form of (fedexURL & trackNum) (*& " | awk '/Signed for by / {print $4}' | cut -f 1 -d '<' "*)
you should use quoted form always in strings containing spaces and other special characters (like & and ?)
so far, I’ve been using AWK to get text right next to key words. Like I know how to get the “for by” after “Signed” but since the name I’m looking for isn’t on the same line, but instead below, my ‘key words’, I don’t know how to do that. Any suggestions?
do shell script "/usr/bin/curl -A \"Mozilla/4.0\" -s " & quoted form of (fedexURL & trackNum) & ¬
" | /usr/bin/grep --max-count=1 --context=2 'Signed for by'" & ¬
" | /usr/bin/grep '<TD>[^<]*</TD>'" & ¬
" | /usr/bin/sed -e 's/ *<TD>//' -e 's/<\\/TD>//'"
set whoSigned to result
Edit: Alternatively:
do shell script "/usr/bin/curl -A \"Mozilla/4.0\" -s " & quoted form of (fedexURL & trackNum) & ¬
" | /usr/bin/grep --max-count=1 --context=2 'Signed for by'"
set whoSigned to result
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "<TD>"
try
set whoSigned to text 1 thru -6 of last text item of whoSigned
on error
set whoSigned to ""
end try
set AppleScript's text item delimiters to ASTID