Action for opening attachment or manipulating all attachment links

This plugin creates custom links to attachments links so this way its possible to set expiry date, permissions etc.

I would suggest you to look at the plugin code, adapt the parts that you looking to custom and add your code. This may save you the time finding and testing the attachments hooks and filters.