custom icon in dialog

I have a file in my current directory Icon.png .

How do I make this the icon for an applescript dialog?

I have tried

$ osascript -e 'display dialog "Hey" with icon file "./Icon.png"'
0:54: execution error: File file ./Icon.png wasn’t found. (-43)

So how can I get a local image and use it as the icon in a dialog?

I am happy to convert the image to a .icns if necessary.


As mentioned in the comments, by default AppleScript will not understand a POSIX path, and you need to give it the full one, not a relative one.

osascript -e "display dialog "Hey" with icon POSIX file "${PWD}/Icon.png""

AppleScript requires double quotes and you need them surrounding the code so bash can interpret ${} , which is why there are so many " .

No need to convert your icon to .icns . AppleScript will gladly take your .png .


tell application "System Events" to display dialog "{0}" with icon file (path of container of (path to me) & "Icon.png")

Worked for me. I had to save it in its own file, and I replaced the {0} with the message that needed to be in the dialog at runtime.

链接地址: http://www.djcxy.com/p/56812.html

上一篇: Bash脚本获取完整路径(使用'source'来调用它)

下一篇: 定制图标在对话框中