Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Auto-fill FedEx forms in Safari via AppleScript Web Browsers
If you do a lot of shipping with FedEx, you know how annoying it is to cut and paste all the address information into Safari. There are expensive programs that will extract information, but most don't work with OS X or require Filemaker. Here's a quick hint I use quite often to autofill the FedEx forms.
tell application "Safari"
  activate
  tell (make new document) to set URL to "https://www.fedex.com/ship/shipEntryAction.do?method=doInitialEntry&origincountry=us&locallang=en&urlparams=us&sType=&programIndicator=0"
  delay 2
  
  set doc to document "FedEx | Ship Manager | Shipping"
  log (doc's name)
  do JavaScript "document.forms['domesticShipmentActionForm']['recipient.companyName'].value = 'add'" in doc
  do JavaScript "submitForm('doSelectRecipientCompanyName')" in doc
  delay 2
  do JavaScript "document.forms['domesticShipmentActionForm']['recipient.companyName'].value = 'New Company'" in doc
  do JavaScript "document.forms['domesticShipmentActionForm']['recipient.firstName'].value = 'First'" in doc
  do JavaScript "document.forms['domesticShipmentActionForm']['recipient.lastName'].value = 'Last'" in doc
  do JavaScript "document.forms['domesticShipmentActionForm']['recipient.addressLine1'].value = 'Address1'" in doc
  do JavaScript "document.forms['domesticShipmentActionForm']['recipient.addressLine2'].value = 'Address2'" in doc
  do JavaScript "document.forms['domesticShipmentActionForm']['recipient.city'].value = 'City Name'" in doc
  do JavaScript "document.forms['domesticShipmentActionForm']['recipient.stateProvinceCode'].value = 'UT'" in doc
  do JavaScript "document.forms['domesticShipmentActionForm']['recipient.zipPostalCode'].value = '84111'" in doc
  do JavaScript "document.forms['domesticShipmentActionForm']['recipient.phoneNumber'].value = '801-655-1996'" in doc
  do JavaScript "document.forms['domesticShipmentActionForm']['recipientGroundCommercialFlag'].checked = true" in doc
  do JavaScript "recipientGroundCommercialFlag = false" in doc
  do JavaScript "document.forms['domesticShipmentActionForm']['shipmentServiceType'].value = 'FedEx Home Delivery'" in doc
  do JavaScript "document.forms['domesticShipmentActionForm']['shipmentPackagingType'].value = 'Your Packaging'" in doc
  do JavaScript "document.forms['domesticShipmentActionForm']['packageWeightForPieceZero'].value = '1.5'" in doc
  do JavaScript "document.forms['domesticShipmentActionForm']['packageWeightForPieceZero'].value = '1.5'" in doc
  do JavaScript "document.forms['domesticShipmentActionForm']['shipmentDimension'].value = '1006956'" in doc
  do JavaScript "document.forms['domesticShipmentActionForm']['packageDeclaredValueForPieceZero'].value = '70'" in doc
  do JavaScript "document.forms['domesticShipmentActionForm']['shipmentAlert.senderExceptionNotificationFlag'].checked = true" in doc
end tell
You can easily modify this to do more programmically. For instance, I use Python and appscript to parse the emails my e-commerce solution sends, and then fill in the FedEx page with Safari. I'll leave that up to you. Even if you don't need to do that, simply autofilling most of the common fields may be a huge timesaver for you. This also demonstrates an easy way to handle forms in general.

The only bit that needs explanation is the filling in of the field shipmentDimension, which seems a tad confusing. FedEx adds a unique number for each custom box you've created. Go to Safari's View » View Source menu, search for shipmentDimension, and you'll see your custom box sizes and the numbers for each.

Also note the two delay statements which wait two seconds each. That is necessary so that FedEx's custom Javascript code runs. If you have a slow connection, you may need to increase that delay time.
    •    
  • Currently 2.33 / 5
  You rated: 5 / 5 (9 votes cast)
 
[24,850 views]  

Auto-fill FedEx forms in Safari via AppleScript | 6 comments | Create New Account
Click here to return to the 'Auto-fill FedEx forms in Safari via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Auto-fill FedEx forms in Safari via AppleScript
Authored by: Anonymous on Feb 14, '08 08:39:03AM
While this is a great time saving hint I would also point to a great piece of shareware that handles these types of tasks called 1Password:

[link:]http://1passwd.com/

While I didn't think I would use this very much at first it has become one of those programs that I can't imagine using my Mac without.

$30, but worth it in my opinion. If you are constantly filling out forms or have many passwords this is a great and secure way of storing everything.

-A

[ Reply to This | # ]
Auto-fill FedEx forms in Safari via AppleScript
Authored by: ClarkGoble on Feb 14, '08 07:35:59PM

The reason you'd do this instead of using a password filler is if the fields you are filling in are coming from some other data source. As I said FedEx offers a JavaBeans interface but then you lose the ability to revise what's entered. Since FedEx has a very nice address checker which finds customer typos quite often I prefer using Safari. I have a little Python script which scans an email and then fills in the FedEx form. In this way I have a very nice little way of handling shipping from my e-commerce site without paying $5000+ for a more 'professional' (and less Mac-like) program.

Since I spent so long trying to find out how to do this via Google I figured others would probably like this information. Especially if you are doing custom databases.



[ Reply to This | # ]
Auto-fill FedEx forms in Safari via AppleScript
Authored by: Scripter12 on Feb 14, '08 10:24:20AM

Thanks. I've been looking for a way to script some items in Safari and never even thought of looking in the source to access specific Java Scripts.



[ Reply to This | # ]
Auto-fill FedEx forms in Safari via AppleScript
Authored by: ClarkGoble on Jun 03, '08 01:46:33PM
Someone mentioned this doesn't work anymore. That's because FedEx updated their page to a more AJAX like one. I'd updated my script for that but I couldn't for the life of me get it to properly fill out the State correctly because of some hidden script they had running. And I'm just not enough of a Javascript hacker to be able to see what was going on.

Then by accident I discovered that they have the old page up still. It's the one listed as "low bandwidth" when you log in to FedEx.

Change the url in the above script for when you first go to FedEx to this one:

https://www.fedex.com/ship/shipEntryAction.do?method=doEntry&link=1&locale=en_US&urlparams=us&sType=F

That should make it work.

[ Reply to This | # ]
Auto-fill FedEx forms in Safari via AppleScript
Authored by: ClarkGoble on Jun 11, '09 03:25:35PM
I still get lots of emails for the above. FedEx has changed their website quite a bit since I wrote this hint. I put up a longish post with source code at my blog on how to do the auto-fill using Python. (Although it's fairly trivial to modify it for Applescript)

[ Reply to This | # ]
Auto-fill FedEx forms in Safari via AppleScript
Authored by: ClarkGoble on Feb 05, '10 09:02:47PM

Just a note, I still get a lot of links from my above post. Both Safari and FedEx.com have changed a lot since I submitted the original post as well as the blog post I linked to earlier.

Since a lot of people use this I've put up a permanent page with the latest version of the source code. This will work with whatever modifications Apple makes to Safari or FedEx.com makes to their shipping page.

[ Reply to This | # ]