Reputation:
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.
Upvotes: 1
Views: 1443
Reputation: 5705
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
.
Upvotes: 4
Reputation:
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.
Upvotes: 0