Can we open a system dialog from a Console app?

I wish to create a macOS daemon as a Console app. This will monitor for certain device cases and I’d like to pop up a system dialog on certain exceptions. NOTE - Not a simple notification.

Can this be done via a call from a Xojo Console app? Or, am I stuck writing a hidden Desktop app to be able to propagate a popup dialog?

This would be macOS only and built in which ever Xojo API can get it done.

I don’t know the answer on if you can do it directly. But you can at very least then launch UI application from the console application that puts up dialog. (its strange but would do the job)

1 Like

That was my first thought, but hoping there’s something more elegant and system-like :slight_smile:

Instead of a console app, perhaps you could use use a windowless desktop app. You could launch it with no dock icon, so it remains hidden in the background, and then you have access to the full fledged UI.

Search for “hide dock icon” in this forum.

1 Like

Run a shell script:
osascript -e 'display dialog "Warning, error 99" buttons {"OK", "Cancel"} default button "OK"'

the shell will return a string:
button returned:OK

which your console app can parse

See Mac Automation Scripting Guide: Displaying Dialogs and Alerts for a lot more options

4 Likes

Thanks, Mike!

Not only does that allow me to display the dialog I need, but I took it further and opened System Preferences to the Security pane for the user so they aren’t guessing what is meant by the dialog.

Cool! Glad it worked. I’m not sure how notarization and code-signing interact with this - does a console app need special permissions to access osascript? If an app can issue shell commands, it seems like it already has pretty wide permissions, but osascript = applescript which may be special?

Since Osascript is indeed AppleScript, it would not be accepted for a MAS app if it touched Finder or system events. But console is usually not uploaded there, unless for a helper.

1 Like

That’s a good point to make people awere of, I think in this particular case, it is fine as the Apple Script doesn’t appear to be scripting a specific application.

However, it may require all the AppleScript hoops to be checked before release (even outside of the App Store).