Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,025
165
Norway
I would like to make a dialog box which looks something like the attached image, but am having little success...

I haven't found a way to make text in bold and/or italic, so the closest is having two lines and emphasizing the drive name with CAPS, but the following only gives me a generic Applescript icon:
Code:
display alert "Backup done!" as warning message 
"The drive BACKUP can now be disconnected" 
buttons {"OK"} default button "OK"

On the other hand I've been able to add a stop icon (replace "stop" with "1" for a generic Applescript icon or "caution" for a yellow caution icon), but only with one line of text:
Code:
display dialog "Backup done!" 
with icon stop buttons "OK"

I was hoping the code below would do it, but no matter how I arrange the code I keep getting error messages. It seems to concern the second line of text. Here's the code (this time with a custom app icon):
Code:
display dialog "Backup done!" with icon file
"Applications:ChronoSync.app:Contents:Resources:AppIcon.icns" 
with message "The drive BACKUP can now be disconnected" 
buttons {"OK"} default button "OK"

...so what are my options for making a suitable dialog with an icon, two lines of text and prefferably the ability to set the drive name in bold or bold italic? I'm on OSX 10.9.5 Mavericks
 

Attachments

  • backup-done-dialog.png
    backup-done-dialog.png
    24.1 KB · Views: 3,468
Last edited:
You can't mix the the arguments for display alert and display dialog - your last example should be something like:

Code:
display dialog "Backup done!" & return & "The drive BACKUP can now be disconnected" with icon file "Applications:ChronoSync.app:Contents:Resources:AppIcon.icns" buttons {"OK"} default button "OK"

The standard AppleScript dialogs are not customizable beyond the parameters they accept, and do not have any settings for font or text formatting. For that you would need to create your own, for example using the AppleScriptObjC bridge to create a Cocoa panel with a text field containing an attributed string.
 
Thanks, but as Applescript is enough of a challenge for me I think I'll stick with its limitations.

I wrote the following script in order to unmount and alert the user of a finished backup to an external drive in Chronosync:
Code:
tell application "Finder"
	eject disk "Backup HDD"
end tell
display dialog "Backup complete!" & return & 
"Please disconnect BACKUP HDD from your Mac." 
with icon file "Applications:ChronoSync.app:Contents:Resources:AppIcon.icns" 
buttons {"OK"} default button "OK"

But it doesn't work quite as expected because the alert doesn't always come up (I'm sure it worked when I tested it with Chronosync open though). This is in 10.9.5. Mavericks.
Should I use the notification center feature instead (even though it doesn't support using a custom icon as far as I know)?:
Code:
display notification "...disconnect backup drive" 
with title "Chronosync" subtitle "Backup done!" 
sound name "default"
(with the "eject disk" command in there somewhere of course -the above is just what I've tested for the actual dialog).
 
Last edited:
Not sure about your specific issue. Do you get any error messages? What's in the log?

Personally I'd check the disk is mounted before attempting to unmount it:

Code:
tell application "Finder"
	if disk "Backup HDD" exists then
		eject disk "Backup HDD"
		display dialog "Backup complete!" & return & "Please disconnect BACKUP HDD from your Mac."
	end if
end tell
 
Personally I'd check the disk is mounted before attempting to unmount it:
]

Nah. The disk not being mounted is the desired state, so what are you going to do with the condition you're checking for?

Just enclose the unmount in a try block and have the on error clause test for the error code where Finder wasn't able to unmount it.
 
Nah. The disk not being mounted is the desired state, so what are you going to do with the condition you're checking for?

Just enclose the unmount in a try block and have the on error clause test for the error code where Finder wasn't able to unmount it.

Yeah, you could do it with a 'try' block. Either way, if for any reason the disk *isn't* mounted then the original code will error. Personally I prefer to test for an error condition up front rather than let my code error and deal with that error. Just personal preference, I guess.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.