This is not possible in the form that you are wishing it. The reason why it works in a notebook (.nb) is that the underlying Notebook expression has embedded in it the kernel assignments inside of the Cell expression for the cells in question. in contrast, a package (.m) file is just comprised of the code that you are executing and it contains no additional information.