Icons in display dialog

Just an interesting note/question.

I haven’t really used the “with icon blah” statement in the display dialog statements before and I noticed this:

tell application "Finder"
	display dialog "y" with icon 1
end tell

This gives the Mac OS icon whereas this:


	display dialog "y" with icon 1

gives the note icon. The “1” can be replaced with “note” in both instances and the results are the same.

I’m assuming that inside the Finder tell block, applescript looks for an icon in a different location. Where are these icons kept and can I get the standard not icon to be used when inside the Finder tell block?

Thanks,

PreTech

Hi PreTech,

it’s the normal behaviour of display dialog to show the icon of the applcation from which it was called as icon 1/icon note.

Try for example:

tell app “Safari”
display dialog … with icon 1
end tell

D.

Of course, if you prefer a bit of variety…

{{path to "csrv" as Unicode text, {"Finder.app", {{"Which do you prefer?", "generalpref.icns"}, {"What do you want to find?", "find.icns"}, {"For your information.", "info.icns"}, {"Make a new folder?", "new_folder.icns"}, {"Is that a smart folder?", "SmartFolder.icns"}}}, {"Jar Launcher.app", {{"Fancy a cuppa?", "JarLauncher.icns"}}}, {"Crash Reporter.app", {{"Watch out!", "CrashReporter.icns"}}}, {"Help Viewer.app", {{"Help!", "HelpViewer.icns"}}}, {"BOMArchiveHelper.app", {{"Zip me up...", "bah.icns"}}}, {"Certificate Assistant.app", {{"That you, Jeeves?", "Certificate Assistant.icns"}}}, {"Classic Startup.app", {{"Remember me?", "Classic.icns"}}}, {"Conflict Resolver.app", {{"Round we go!", "Sync Services Icon.icns"}}}, {"Dock.app", {{"Just like to say...", "dockling.icns"}, {"...what a great show!", "Dock.icns"}, {"Widget, anyone?", "widget.icns"}}}, {"MirrorAgent.app", {{"I foresee a bright future...", "iDiskGenericIcon.icns"}}}, {"Network Diagnostics.app", {{"...just needs a little work...", "Network Diagnostics.icns"}}}, {"Software Update.app", {{"...and it'll be just fine.", "Software Update.icns"}}}}, {path to "apps" as Unicode text, {"Dashboard.app", {{"Weather looks good.", "Dashboard.icns"}}}, {"Calculator.app", {{"Just trying to figure out...", "Calculator.icns"}}}, {"Chess.app", {{"...my next move.", "chess.icns"}}}, {"Image Capture.app", {{"Smile!", "ImageCapture.icns"}}}, {"Preview.app", {{"Great shot!", "preview.icns"}}}, {"iCal.app", {{"What's the date?", "App.icns"}}}, {"Dictionary.app", {{"What did you say?", "Dictionary.icns"}}}, {"Utilities:Keychain Access.app", {{"Looks just like you.", "vCard.icns"}, {"Anyone seen my keys?", "Keychain.icns"}}}, {"Utilities:Audio MIDI Setup.app", {{"Ah - there they are!", "AudioMIDISetup.icns"}}}, {"Utilities:Terminal.app", {{"Anything good on TV?", "icon.icns"}}}, {"Utilities:Activity Monitor.app", {{"Yeah - this bit's gripping.", "ActivityMonitor.icns"}}}, {"Utilities:Migration Assistant.app", {{"No overtaking.", "MigrateAsst.icns"}}}, {"iMovie.app", {{"That's a wrap.", "app.icns"}, {"G'night, folks.", "iMovie.icns"}}}}}

repeat with x in result
	set a to x's item 1
	repeat with y in rest of x
		set b to y's item 1
		repeat with z in y's item 2
			try
				display dialog z's item 1 with icon a & b & ¬
					":Contents:Resources:" & z's item 2 as alias giving up after 2
			on error number n
				if n is -128 then error number n
			end try
		end repeat
	end repeat
end repeat

Holy Icon Batman! I think Madonna’s dead!

:o I say :o

I guess that gives me an idea of where the icons are ;).

Thanks to you both!

PreTech

:lol::lol::lol: Sorry about that, PreTech. Just a bit of fun, really - although I suppose it demonstrates that one can “borrow” an icon from pretty much anywhere.

In case it might be more helpful to someone, here’s a rather less… entangled approach:

set p to "/Applications/Internet Connect.app"
display dialog "Connect to the Internet?" with icon path to resource "NetworkConnect.icns" in bundle POSIX file p

I haven’t tried it Kai, but could you save an AppleScript as a bundle, stick a resourses folder in it, load in some icons of your own making, and then refer to them with icon path to resource… as you have above?

I like this one (path courtesy Gnarlodious) that I’ve dressed up a bit:

display dialog "Question of User" with title "Query Dialog" default answer "Default
answer" with icon (path to resource "GenericQuestionMarkIcon.icns" in bundle ((path to library folder from system domain as string) & "CoreServices:CoreTypes.bundle") as alias)

There are lots of others you don’t often see in there - check out any of them that’s fairly large in size - the small ones pixelate.

These are the ones I like to use: AlertNoteIcon.icns, AlertStopIcon.icns, BurningIcon.icns, CDAudioVolumeIcon.icns, HomeFolderIcon.icns, TrashIcon.icns, Unsupported.icns

Sure. Let’s say you’ve added an icon file called “MovieFolderIcon.icns” to the Resources folder of your bundle. You can then get your script to display a dialog using that icon with something like:

display dialog "Call me Holly Wood." with icon path to resource "MovieFolderIcon.icns" in bundle (path to me)

You can also take another icon of your choice, rename it “applet.icns” and drop it into the Resources folder of your bundle, so that it replaces the existing icns file. It may take a while to persuade Finder to recognise the change, but your app will then take on the appearance of the inserted icon. (If all else fails, duplicating the app file should cause the icon to show up.)

I’m pretty sure I was involved in some of the discussions way back, when Gnarlie and others were exploring the question of icons. Here’s one of the gizmos I came up with to present the icons in CoreTypes.bundle:

set p to (path to "csrv")'s POSIX path & "CoreTypes.bundle/Contents/Resources/"
repeat with i in list folder POSIX file p without invisibles
	if i ends with ".icns" then display dialog i's text 1 thru -6 buttons {"Cancel"} with icon POSIX file (p & i) giving up after 1
end repeat

As always, very neat. Thanks.

Is there any way to get the size of those files? Only the big ones really look good.

Yeah - some of those older ones are definitely showing their age, Adam. Since most of the really scruffy ones are below about 10 KB, something like the following should do the trick (although you can adjust the size filter to taste):

to show_icons over k for t
	set p to (path to "csrv")'s POSIX path & "CoreTypes.bundle/Contents/Resources/"
	set l to list folder POSIX file p without invisibles
	set e to count l
	set q to true
	set b to "+"
	set m to 1
	repeat
		set f to l's item m
		set i to POSIX file (p & f)
		set s to ((size of (info for i)) + 500) div 1000
		if f ends with ".icns" and s > k then
			set d to f's text 1 thru -6 & return & s & " KB"
			if not gave up of (display dialog d buttons {"Cancel", "Pause"} default button 2 with icon i giving up after t) then ¬
				set b to button returned of (display dialog d buttons {"Cancel", "-", "+"} default button b with icon i)
			if q then set q to false
		end if
		set m to m + (b & 1)
		if m > e then
			if q then return beep
			set m to 1
		else if m < 1 then
			set m to e
		end if
	end repeat
end show_icons

show_icons over 10 for 1 (* over size (KB), for time (seconds) *)

Now that is really slick, Kai. Terse, but slick. Thanks

This is exactly what I’m trying to do! See thread http://bbs.applescript.net/viewtopic.php?id=16693
I can’t find where the iTunes icon is located, though…

Hi Slim,

The iTunes icon is here:

set f to “Macintosh HD:Applications:iTunes.app:Contents:Resources:iTunes.icns” as alias

on my computer. Jaguar’s ‘display dialog’ command can’t use icon references I think, so I can’t check if using this reference works.

As I mentioned in the other post, if you’re writing a script app, you could add a “cicn” resource to the app and use that icon.

Edited: hoping that I’m not going to get scoldings for mentioning an old fashioned method.

gl,

Just to confirm Kel’s advice, this works in Tiger: Edit: cleaned up path (see below)

display dialog "iTunes" with icon path to resource "iTunes.icns" in bundle (path to application "iTunes")

However, also in Tiger, a dialog displayed by an application (such as in Slim’s script, should automatically display that app’s Aqua icon for note/icon 1 (as Dominik mentioned earlier in this topic).

This variation of Slim’s script, for example, shows the iTunes logo in the dialog:

tell application "iTunes" to tell library playlist 1
	set shuffle to not shuffle
	display dialog "Shuffle O" & {"ff", "n"}'s item ((shuffle as integer) + 1) buttons "Sweet" default button 1 with icon 1
end tell

kai, why do you do POSIX file (POSIX path of **) and not just path to ** ?

It may have something to do with the fact that I’ve been up all night (5:30 AM here), working on a project for which the deadline is due in 3 hours time - and have still been trying to squeeze in the odd reply to this forum, Qwerty. Well spotted. :slight_smile:

Edit: On reflection (if I remember correctly), the direct reference didn’t work in an earlier version. But since it clearly does now, that simplifies things considerably. :slight_smile:

display dialog "Final collection." with icon path to resource "TheCheat.icns" in bundle POSIX file (POSIX path of (path to me))

I keep getting an error "Expected end of line, etc. but found ". at the first " mark of TheCheat.icns

Is the word resource a variable?

What am I doing wrong?

That compile-time error is possible with a broken line, PUNCH:

display dialog "Final collection." with icon path to 
resource "TheCheat.icns" in bundle (path to me)

I realise you’ve posted a single statement above - so there may be another problem involved. However, the term ‘resource’ should normally compile as a keyword, not a variable:

display dialog "Final collection." with icon path to resource "TheCheat.icns" in bundle (path to me)

Some icons:
http://interfacelift.com/icons-mac/index.php?sort=date

Some nice stuff there, Mark. :slight_smile:

Ok, I put just that line in a scriptwindow, and got this error:

A " can’t go after this identifier.

I’ve tried putting it in a Finder tell, and several other variations.

What am I doing wrong?

display dialog "Final collection." with icon path to resource "TheCheat.icns" in bundle (path to me)