Forums

Script determine where it's running from

Hello!

I finally managed to make my first scheduled task, only 1 minor question: Is there a way for my script to determine where it's running from?

I'd like it to behave a certain way if it's running as a scheduled task versus me running it manually or even lately it getting called from the web app.

Thank you!

You could look at the machine's hostname using socket.gethostname() -- if it contains task then your code is running in a scheduled task, if it contains console then you're running in a console, and if it contains web then it's in a web app.

Great, that seems to have done the trick, thanks

No problem! For completeness, I should mention that if you want to check if you're running in an always-on task, then you can look for alwayson in the hostname.