For custom actions and scripts you need to get action ID that Reaper has the script's GUID - "_ah4wp93pa98uf1awhatever" assigned to.
This is how I do it in Lua, along with some error checking:
Code:
-- 'act' is the action/script ID in a string
-- Scripts and custom actions all use the same format for their GUID,
-- so you just need to see if the string starts with a '_'
if string.sub(act, 1, 1) == "_" then
act = reaper.NamedCommandLookup(act)
end
-- Not strictly necessary, but Lua doesn't always like it when you try
-- to use a string as a number
act = tonumber(act)
-- Make sure that:
-- a) tonumber() worked, and
-- b) we have a useable action ID
if act and act > 0 then
reaper.Main_OnCommand(act, 0)
end