How to make a script run by osascript hide able

I have a script which needs to use osascript to call another script in background. That is so the first script can continue on with further actions. The called script displays an “enhanced window” using the Dialog Toolkit. The resulting dialog cannot be hidden. Thus it obscures other apps etc. Is there a way of enabling the window to be hide able ?

This is a cut down version of the first script:

set test_call to quoted form of "/Users/home/Desktop/Testcallingenhancedwindow.scpt"
do shell script "osascript -s s " & test_call & " " & " > /dev/null 2> /dev/null &"
-- Lots more code follows unrelated to the displayed window

This is the called script (Testcallingenhancedwindow.scpt):

use AppleScript version "2.4"
use scripting additions
use script "DialogToolkitPlus" version "1.1.1"
set accViewWidth to 200
set {theButtons, minWidth} to create buttons {"Cancel", "OK"} cancel button 1
if minWidth > accViewWidth then set accViewWidth to minWidth
set {boldLabel, theTop} to create label "Just a test" bottom 20 max width accViewWidth control size regular size
set {buttonName, controlsResults} to display enhanced window "Many Buttons" acc view width accViewWidth acc view height theTop acc view controls {boldLabel} buttons theButtons

The window seems to be displayed by osascript (its parent ?). I can’t figure out a way of enabling the user to hide that window so that it doesn’t obscure other apps. A minimise function would be an alternative.

Thanks.

Garry

Model: MacBook (late 2008)
AppleScript: 2.4
Browser: Safari 12.1
Operating System: macOS 10.14

If they hide it, they’ll never be able to get it back. You can make it minimisable by adding NSMiniaturizableWindowMask to the existing styleMask: parameter when the window is created (or just set its styleMask property at some later stage). I just don’t know how that will work, because you have no Dock icon for it. The other option is to play with the level property.

Your problem stems from the fact that you’re showing it from a background-only process.

Shane, many thanks. Yes, I have thought it would not be possible to do this with a background process, although I’ve used a background process to tell Finder to display a dialog which is hide able together with the Finder. But, I need four buttons so, that will not do in this case.

I’ve played with NSWindowStyleMaskMiniaturizable - the best I got was with value of “2” which resulted in a functioning close button but the minimise and zoom buttons were greyed out.

Tried NSNormalWindowLevel which made no difference - the other level options don’t seem more relevant.

Cheers.

Garry

P.S. Have to note that finding out what values are valid is very hard - sometimes Apple’s documentation shows the valid range but other times not. Best sources have been posts on MacScripter and StackOverflow !

I’ve managed to find a way to make a dialog displayed by a background osascript hide able. It’s possible if the script which displays the enhanced window is an applet. This is the code:

 do shell script "osascript -e 'tell application \"Macintosh HD:Users:[home]:Desktop:Testcallingenhancedwindow.app\"' -e 'launch' -e 'called_by_script(\"Show this\")' -e 'end tell' > /dev/null 2> /dev/null &" 

The script containing the osascript call continues on and the applet displays the hide able window. Because it’s an applet, it has its own menu and can be hidden.

If I run that osascript call multiple times, the multiple instances of the applet run in succession. However, I need to be able to run a number of instances of the applet at the same time ie. show more than one window. To try to get multiple instances running, I tried pre-pending with “open -n” instead of launch but, my applet returned that it didn’t understand the “open” message.

Also, I’ve not been able to get the osascript call to take variables. For example,

 set path_name to path to [applet]
do shell script "osascript -e 'tell application path_name' -e 'open' -e 'called_by_script(\"Show this\")' -e 'end tell' > /dev/null 2> /dev/null &" 

It returns the error “The variable path_name is not defined”.

I think I’ll give up.

Cheers.