Sample lua code:
local spellNameInGame = "Charge";
local freeslot = -1;
for i=1, 120, 1 do
if not HasAction(i) then freeslot = i; break; end
end
if freeslot <= 0 then return; end
local i = 1
while true do
local spellName, spellRank = GetSpellName(i, BOOKTYPE_SPELL)
if not spellName then break; end
if spellName == spellNameInGame then PickupSpell(i, BOOKTYPE_SPELL); PlaceAction(freeslot); ClearCursor() end
i = i + 1
end