I know that a sentence that ends in the て form of a verb can be imperative. How do you know for sure if it is? Why is「～しようとして」not imperative?
しようとして (and all the forms in ようとして：食べようとして...etc.) can all be perfectly correct requests or commands depending on how the sentence ends.
To understand this, you need to know that the よう form of a verb is called Volitional and is used (in brief) to say "let's do..."
Now, adding として to this volitional form, it should be decomposed as follows:
-と is the particle (same as と言う、と思う)
-して (て form of する)
- If the sentence doesn't end after the て form:
The insect was about to eat grass when he got eaten by a bird.
Then the て form is used to combine sentences (see the Wikipedia article above). ようとして then means "to be about to" or "try to".
- On the contrary, if the sentence ends with として, then you have the request form.
The volitional form of a verb + として corresponds to the English "(Please) Try to...". (you can still add ください、ほしい、くれ...etc. like for any other request) It's a very natural way to request someone to do something and see how it goes.
Some widely used examples to illustrate this:
(browser doesn't display flash) フラッシュをダウンロードしようとしてください。Please try to download flash.
(internet connection lost) 再度接続しようとしてください。Please try to reconnect.
このポイントを明らかにしようとしてください。Please try to clarify this point.
て is a form that is quite basic (called gerund, infinitive, or participle in modern linguistics depending on the researcher) and has different usages. Among the various usages, it can be used as an omitted form of
...てください 'please do ...' or
...てほしい 'I want you to do ...', expressing request with various strength depending on the context, but it cannot be imperative. Imperative is
しようとして can be used as request but is not natural because, if you want someone do something, you would simply say