If the spell in question is 6th level or lower (or if you forward-port Lords of Madness's 9th level version) and includes (or can be modified to include) some harmful component, Greater Glyph of Warding can do the trick. This particularly useful for barkskin, iron body (with spell level lowering abilities or Lords of Madness), and the like, which can legitimately be used for offensive purposes when forced onto an opponent, but can also be used to buff allies on the side.
If the spell in question is on the Alchemist list, it can be made as an extract and thus used to affect other allies via shenanigans.
If the spell in question is really low level, you can give it to others via Imbue with Spell Ability, though if what you want is for someone else to take the action to produce the spell effect but that effect to end up on you, that won't work, of course.
Magic Jar sort-of lets you swap buffs, by swapping bodies instead.