Is there a way for a Cocoa application to tell if it's being run interactively or from something like cron? Basically I want to have the GUI appear if it's a person running the command, but if it's being called from something like cron, then I don't want the GUI to show.
Asked
Active
Viewed 121 times
4
-
Maybe you can implement `--nogui` argument – Bryan Chen Jul 14 '13 at 22:52
-
Sure, but I was hoping for a way for the app to determine this itself. – Gargoyle Jul 14 '13 at 22:55
-
but you will remove the possibility to run your app with gui from script/terminal – Bryan Chen Jul 14 '13 at 23:03
-
If I manually run a script that calls this app, it would still see that it has a controlling TTY, and the GUI would appear like normal. I'm looking for something similar to the "-t 0" check in perl. – Gargoyle Jul 14 '13 at 23:06
-
Are you interested in whether you can have a GUI, or whether your app is being run from the Terminal? Running an app from the Finder will not give it a TTY, but it still should show a GUI. – Peter Hosey Jul 15 '13 at 02:59
-
Whether it can have a GUI. – Gargoyle Jul 15 '13 at 03:28
2 Answers
0
Sounds like you are looking for the isatty
function (which is probably what perl's -t
test uses).
if (isatty(0)) {
// standard input is a “tty” hence I should run interactively
}

rob mayoff
- 375,296
- 67
- 796
- 848
-
When the application is started from the Finder, [that expression returns false](http://i.stack.imgur.com/HlB43.png). I asked the questioner for clarification in the comments on the question; it appears that the presence of a TTY specifically is not actually what they are interested in. – Peter Hosey Jul 15 '13 at 05:05
0
You can use launchctl list
command.
With no arguments, list all of the jobs loaded into launchd

Parag Bafna
- 22,812
- 8
- 71
- 144