yes, int slot = getSlotForId(KNIFEID) return the first slot in the inventory where the knife is located. If you folow this up by selectInventoryOption(slot, "Use") it will work,
but from what I can remember getSlotForId is bugged you could try it anyways