You can only do this with an api call the webhook is called "app/uninstalled" documentation on registering a webhook can be found here
http://docs.shopify.com/api/webhook
One thing to be mindful of is it can take a few minutes to come through and you can't use an address only your machine can handle such as "http://localhost"