Generic (path-independent) alias to the icon of an application

For display dialog I need the alias to my application’s icon. At the moment I do it like this:

set theIcon to alias "fence:Applications:Optional:MyApplication.app:Contents:Resources:AppIcon.icns"
set ans to display dialog "Input" with icon theIcon

This is not very portable (when I move the app somewhere else or when I give the script to somebody who has the same application). Is there any generic (path-independent) way to get an alias to the icon of an application?

Something like this?

"" & (path to applications folder) & "Optional:MyApplication.app:Contents:Resources:AppIcon.icns"

Hi.

With the icon file at that location in your app bundle and your application running the script:

display dialog "Input" with icon (path to resource "AppIcon.icns")

This only works if your app is the one displaying the dialog ” ie. when the command’s not in a ‘tell’ statement directed at another application. If you want another application to display a dialog with your icon, it would have to be something like:

tell application "Finder" -- For instance.
	display dialog "Input" with icon (path to resource "AppIcon.icns" in bundle (path to me))
end tell

That’s exactly what I needed! Thanks a lot!