You need to avoid the bed normal activation kicking in. For that, you need to use the blockactivaion function.
In the case of the script on a bed:
Event OnInit()BlockActivation()EndEvent
Then add an onactivate event with what you want the bed to do, and once you need the bed to be activated:
self.activate(game.getplayer(), true) ; the 'self' word is unneded here but it's handy so you can get easier the use of the function.;let's say that The player didn't activate the object the object makes the player activate it.
If you wan't to allow the bed to be activated as always:
Blockactivation(false)
Anyway, this approach is a great error, as you will put a script directly on any bed you want to use, which I assume are all. So, the script will be there even if the mod is uninstalled.
To avoid this, add a permanent cloack spell with the required script, to the player, detecting beds and adding the spell to them. Use the oneffectstart event instead of the oninit one, and add a check to ensure that it didn't work on the player (just add an if block surrounding commands). When the player is near enough, the spell will be added to the bed and when the mod is removed the spell will disappear from the player and all the beds.
This link will help you with the cloack spell part: http://www.creationkit.com/Dynamically_Attaching_Scripts
EDIT: I forgot to add that you will need to check on the onactivate block that the one activating it is the player. Just:
Event OnActivate(ObjectReference akActionRef)If aktionRef == game.getplayer();Use here the animationutility.wait(3) ; instead of 3 just put the time you judge appropriateself.activate(game.getplayer(), true) EndifEndEvent