[v5 volitional (〜おう)] + としたが [v1 volitional (〜よう)] + としたが [する → しよう] + としたが [来る → 来よう(こよう)] + としたが
Note: が may be replaced by けど/けれど(も) for a softer tone.
The structure としたが is used to express that someone tried to do something but couldn't, or was about to do something but something happened to prevent it. It conveys the idea that an action was attempted or on the verge of happening, but the expected outcome did not occur.
It is formed by attaching とする (which means "to try to" or "to be about to") in its past form とした to a verb's volitional form, followed by が ("but") to introduce the contrasting result.
This is the most common usage – someone tried to do something but was unable to or was interrupted.
としたが can also describe a situation where someone was just about to do something when something else happened, preventing it.
The conjunction が can be replaced with other contrast markers like けど (casual) or けれども (more formal) without changing the core meaning:
When the sentence ends without a second clause, としたが can trail off to imply the result: