Hey, Thomas, here are a couple of things to look at...
Unnecessary forselected
First, you're only Spawning a single token, it looks like, from a single character. For that you won't need the forselected handle... just the {&select ... } structure. You don't need to iterate over selected tokens if you only have one token selected, and that looks like what you're doing with the {&select ... } syntax.
Attribute Retrieval Problem
Also, it looks like you want your spawnList variable to be an array of attributes, except you're feeding a flat name value to the findObjs() function:
var spawnList= findObjs({ type: 'attribute', _characterid: character.get("_id"), name: "spawn_with"});
That will only find attributes named "spawn_with", exactly. Later you want step through the array to retrieve attribute values from those attributes, but your list is likely empty. Either it's empty, or there's no way to differentiate one from another because they all have the same name (yes, you can have attributes that share a name on a character sheet, which leads to the sort of problems you can imagine).
Can you describe your setup and what you're trying to do? For instance, if your setup is that on each character you have a series of attributes like:
spawnwith_offsetx
spawnwith_offsety
spawnwith_sizex
spawnwith_sizey
...and you wanted to retrieve the max value from each as the values to feed to your Spawn command, I would approach that from one direction, but with a different setup, I might approach it a different way.
Command Line - Who are you?
All of that is going to lead to (what I imagine will be) a bad command line, but as for why whatever-this-generates working as a command line for you when you paste it into chat versus when it runs from the script... that's likely a matter of the difference between script- and user-generated messages. There is more data for a user-generated message (things like "who" sent the message, the playerid of the sender, and selected tokens). For a script-generated message, there is none of that.
You can work around that by configuring SelectManager to give those things back:
!smconfig +playerid +who
SelectManager "ships" preconfigured to only give back the selected tokens, but you can turn on the other properties with the above command line. That will likely make your command line work from your script... however you'd still not need the forselected handle, and you're likely not getting the data you want to get from the attributes you're looking for.
Fetch
Unless what you've shown here is part of a longer process -- or if you're just trying to learn scripting -- what you've shown can be handled in the chat at game-time using fetch constructions. If your setup is that you have attributes named as above (ie, "spawnwith_xoffset"), I think it would look like:
!Spawn --name|@{selected|token_name} --offset|@(@{selected|token_id}.spawnwith_offsetx),@(@{selected|token_id}.spawnwith_offsety) --size|@(@{selected|token_id}.spawnwith_sizex),@(@{selected|token_id}.spawniwth_sizey)
(Air-coded caveats apply)
The expectation, here, is that you'd have the token selected from whose associated character sheet you would want to draw the offset/size... but I think that's what your original code reflected, too. Note that you don't need the {&select ...} construction since you're no longer working with a script (you'd be sending this as an ability macro to chat). Instead, you just need fetch to get the attributes from the associated character sheet.
Of course, if I've misunderstood what you have going (or, like I said, you want to learn coding) then post back with more information and we can get it sorted.