Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Use icons instead of buttons in display dialog?

Rather than "display dialog "Something" buttons {"1", "2", "3"}", can I have them click on icons of my choosing instead of buttons?

 MacBook Pro with Retina display-OTHER, OS X Mavericks (10.9.5), 15 in, Late 2013, 256GB, 8GB RAM

Posted on Jul 2, 2015 6:51 PM

Reply
Question marked as Best reply

Posted on Jul 2, 2015 6:56 PM

No, unless those icons are available as emojis.


(129578)

6 replies

Jul 2, 2015 8:28 PM in response to Niel

I was afraid of that... thanks. If I could tack another AppleScript question on here, could you help me with the following?


I want to use System Events' "keystroke" command to control the Finder as follows:


tell application "Finder"

set the clipboard to (POSIX file "/Users/SJF/Desktop/IMG_0118")

set filepath to POSIX file "/Applications/iTunes.app" as alias

open information window of filepath

tell application "System Events"

--perform action "AXRaise" of window 1 of process "Finder"

tell application "Finder" to activate

keystroke tab

tell application "Finder" to activate

keystroke "v" using command down

tell application "Finder" to activate

keystroke "w" using command down

end tell

end tell


...however, the keystrokes get carried out on the script's window and not Finder's.

Jul 2, 2015 8:41 PM in response to stevejobsfan0123

I got that to work by preselecting the desired field in the Get Info window and using:


tell application "System Events"

tell application "Finder" to activate

keystroke "v" using command down

keystroke "w" using command down

end tell

end tell


If you want to change the item’s name or comment, you can interact with it directly instead of using System Events.


(129587)

Jul 5, 2015 12:29 AM in response to stevejobsfan0123

If you prefer not to dive into Xcode or AppleScriptObjC, the scripting addition 24U Appearance OSAX 4.0 offers additional options, including for buttons, albeit not icon buttons. It offers radio buttons, pop-up menus, check boxes, validation text fields, unlimited buttons for dialogs, size and position window control, etc.


If you decide to download the OSAX, you can access script samples from the installer package's Appearance OSAX Extras/Examples folder. Option-click on an AppleScript app in the folder and choose "Show Package Contents". Navigate to Contents > Resources > Scripts > main.scpt. View with Quick Look by pressing the Spacebar key, or double-click to open in Script Editor. The apps themselves may not run, although the scripts do. Also make use of Script Editor's dictionary (Command-Shift-O) for use, syntax, and examples.


You can spice up your dialogs with image or ICNS files. Just provide a file path to the resource. A typical path is something like: ("Users:<username>:Pictures:MyImage.png" as alias). You can find System and Application icons to use on your computer. System icons can be found at /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/. Application icons can be found by Option-clicking on an app icon, choosing "Show Package Contents" and navigating to Contents > Resources. Copy the ICNS file to a location of your preference or provide a path to it. Here's a path example to a System icon:

with icon (path to resource "GenericApplicationIcon.icns" in bundle ((path to library folder from system domain as string) & "CoreServices:CoreTypes.bundle") as alias)

You'll need to size the image or ICNS appropriately to your design. If you find an icon too large for your needs, open it in Preview and use one of the PNG images that comprise an ICNS file and resize it. Image formats that support transparency (alpha channel), such as PNG or TIFF, work best although other formats are usable.


Example using images, pop-up menu, checkbox, and multiple buttons:

User uploaded fileUser uploaded file

User uploaded fileUser uploaded fileUser uploaded file


The code:

set dialogResult to display better dialog "Pick a fruit:" fields ¬ {{kind:popup menu, field menu items:{"cherry", "pear", "apple"}, field value:"cherry"}, ¬ {kind:check box, name:" with chocolate fondue", field value:checked state}} ¬ with icon ("Users:pd:Desktop:Fruit384x128.tiff" as alias) ¬ buttons {"Yum", "Fresh", "Sweet", "Bittersweet", "Bitter", "Rotten", "Yuck"} ¬ default button 1 title "Dessert" set buttonReturned to button returned of dialogResult as text try do shell script "echo " & quoted form of (buttonReturned) & " | tr A-Z a-z" set lowerString to the result end try set fruitChoice to field value of item 1 of fields returned of dialogResult if fruitChoice is "cherry" then set fruitIcon to ("Users:pd:Desktop:Cherry234x247.tiff" as alias) else if fruitChoice is "pear" then set fruitIcon to ("Users:pd:Desktop:Pear216x247.tiff" as alias) else if fruitChoice is "apple" then set fruitIcon to ("Users:pd:Desktop:Apple229x247.tiff" as alias) end if end if end if display better dialog " You prefer " & choices returned of dialogResult & " and a slice of " & lowerString & ¬ "!" title "What You Prefer" with icon fruitIcon buttons {"OK"}


Another example using a GIF and radial buttons:

User uploaded fileUser uploaded file

Use icons instead of buttons in display dialog?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.