Sunday, September 15, 2019

#1 2019-04-23 07:07:53 pm

hansolo625
Member
Registered: 2019-04-17
Posts: 20

2 Quick Inquiries: Display Dialog & Radio Buttons

Hi expert scripters!

Novice/Intermediate scripter here. Thanks to all the support and online resources, I've managed to create a few super useful tools with AppleScript for my team, which I'm super proud of. I've got two quick questions that I couldn't find solid answers online on my own.

First, many of my scripts require a pop-up window. It can be Display Dialog with customized buttons or Choose From List options. The issue is that if I have multiple desktops, and I execute the script with a keyboard shortcut/command from a 3rd party tool (TextExpander), the pop-up window would only appear at the desktop where the script is executed. For example, if I have TextExpander placed on Desktop1 and I'm working on Desktop2, I entered my keyboard command to run the script via TextExpander, the pop-up window would only appear on Desktop1 while I'm on Desktop2.

Is there any scripting solution to that or must I just change the way the script is executed? (For example using drop-down menu with the Editor Menu option, or creating a Quick Action with the script in my mac, etc)

Second, can AppleScript create dialog with multiple radio buttons? From reading the Mac Automation Scripting guide, it doesn't appear AppleScript is capable of generating radio buttons. The goal is to gather multiple Y/N questions from user without having to pop up 4-5 windows asking Y/N.

Your insight is much appreciated!

Offline

 

#2 2019-04-23 08:42:03 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5881

Re: 2 Quick Inquiries: Display Dialog & Radio Buttons

hansolo625 wrote:

can AppleScript create dialog with multiple radio buttons?



Sure. Go here:

https://www.macosxautomation.com/apples … _Libs.html

and download Dialog Toolkit Plus.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2019-04-24 12:50:42 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 516

Re: 2 Quick Inquiries: Display Dialog & Radio Buttons

hansolo625 wrote:

Hi expert scripters!

Novice/Intermediate scripter here. Thanks to all the support and online resources, I've managed to create a few super useful tools with AppleScript for my team, which I'm super proud of. I've got two quick questions that I couldn't find solid answers online on my own.

First, many of my scripts require a pop-up window. It can be Display Dialog with customized buttons or Choose From List options. The issue is that if I have multiple desktops, and I execute the script with a keyboard shortcut/command from a 3rd party tool (TextExpander), the pop-up window would only appear at the desktop where the script is executed. For example, if I have TextExpander placed on Desktop1 and I'm working on Desktop2, I entered my keyboard command to run the script via TextExpander, the pop-up window would only appear on Desktop1 while I'm on Desktop2.



display dialog in Applescript is modal. This means: you can't show multiply dialogs at time. But you can show 1 dialog, close it, then open other dialog an so on.

Try this:

1) Open 2 windows in Finder. Don't close them.
2) Run script:

Applescript:

tell application "System Events"
   tell application process "Finder"
       tell window 1
           click -- here needed extra mouse tool command
           display dialog "I am desktop 1" giving up after 2
       end tell
       tell window 2
           click -- here needed extra mouse tool command
           display dialog "I am desktop 2" giving up after 2
       end tell
   end tell
end tell

As AppleScript can't send real mouse click events to windows, you must replace "click" (in this script) with click on certain position of screen (on needed window), using one mouse clicks tool, such as MouseTools

Another method is - to run different display dialogs depending on the name or ID of the current front Finder window. Here no need extra mouse tool

Last edited by KniazidisR (2019-04-24 02:26:52 am)


macOS Mojave -- version 10.14.4
Safari -- version 12.1

Offline

 

#4 2019-04-24 08:18:31 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3576

Re: 2 Quick Inquiries: Display Dialog & Radio Buttons

The perfect answer is given by Shane's Dialog Toolkit Plus.

Have a look at its Complex sample.scpt file.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 24 avril 2019  16:18:26

Last edited by Yvan Koenig (2019-04-24 08:28:47 am)

Offline

 

#5 2019-04-25 05:53:23 pm

hansolo625
Member
Registered: 2019-04-17
Posts: 20

Re: 2 Quick Inquiries: Display Dialog & Radio Buttons

Shane Stanley wrote:


Sure. Go here:

https://www.macosxautomation.com/apples … _Libs.html

and download Dialog Toolkit Plus.



WHAT!!!! LOL wow this is SUPER interesting. Thank you so much for sharing this. I'm so noob with the scope of AppleScript I get surprised everytime I ask a question here.

So if I'm interpreting this correctly, one could "script" using AppleScript to expand the default capability of AppleScript? That's wild. lol

Offline

 

#6 2019-04-25 06:24:37 pm

hansolo625
Member
Registered: 2019-04-17
Posts: 20

Re: 2 Quick Inquiries: Display Dialog & Radio Buttons

KniazidisR wrote:

display dialog in Applescript is modal. This means: you can't show multiply dialogs at time. But you can show 1 dialog, close it, then open other dialog an so on.



Thank you KniazidisR! I think I may have not made my inquiry clear. I'm not trying to have multiple pop-up windows at once. The issue is "where" the pop-up window will appear from the display dialog command. When you have multiple desktops created on your Mac and you execute your script by using a 3rd party tool via my pre-defined keyboard shortcut, the pop-up window will only appear on the desktop where the 3rd party tool is located. Therefore if I'm working on Desktop 2 I will have to switch to Desktop 1 to operate the pop-up window.

But given what you said, it appears that display dialog has it's limit.

I thought I can do something simple like

Applescript:


display dialog in desktop 2

but evidently that's not how it works lol

Regardless, I appreciate your input greatly!

Offline

 

#7 2019-04-26 12:04:04 pm

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 414

Re: 2 Quick Inquiries: Display Dialog & Radio Buttons

Looking at previous responses, it looks like the Radio Button question was answered (use Shane's Dialog Toolkit), but I it doesn't look like there's an answer regarding getting the dialog on the right desktop.

There may be situations where this doesn't work - but you might try something like this:

Applescript:


tell application "System Events" to set appPath to (path to the frontmost application)
set appName to the name of (info for appPath)
set appName to text 1 thru ((offset of "." in appName) - 1) of appName

tell application appName
   display dialog "whatever"
end tell

So it finds out what application is in front, then always has that application display the dialog.


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

#8 2019-05-02 01:33:18 am

hansolo625
Member
Registered: 2019-04-17
Posts: 20

Re: 2 Quick Inquiries: Display Dialog & Radio Buttons

t.spoon wrote:


So it finds out what application is in front, then always has that application display the dialog.



That is GENIUS!!! I will try that out for sure!! MUCH appreciated!

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)