有没有办法将自定义图标与 applescript 显示对话框和通知一起使用?
在 AppleScript 文档中,它提到了显示对话框:
with icon
(text | integer)
The resource name or ID of the icon to display.
with icon
(stop | note | caution) The type of icon to show. You may specify one of the following constants:
- stop (or 0): Shows a stop icon
- note (or 1): Shows the application icon
- caution (or 2): Shows a warning icon, badged with the application icon
with icon
(alias | file) An alias or file specifier that specifies a .icns file.
所以看起来你可以使用自己的图标,但我无法让下面的代码工作。
display dialog "Text" with icon "/Users/user/Desktop/asd.icns"
它给我以下错误:“找不到资源。”
我们的目标是甚至不使用显示对话框,而是使用显示通知。
最佳答案
首先,您无法使用 显示通知
显示自定义图标。原因是通知与目标应用程序密切相关。由于 AppleScript 脚本和小程序在 Notification 框架方面不是应用程序,因此通知与 当前应用程序
、AppleScript Runner 有关。
但是您可以使用 显示对话框
线
with icon
(alias | file) An alias or file specifier that specifies a .icns file.
意思是:参数必须是 alias
或 file
说明符,而不是 POSIX 或 HFS 字符串路径。
要么
display dialog "Text" with icon alias ((path to desktop as text) & "asd.icns")
或
display dialog "Text" with icon file ((path to desktop as text) & "asd.icns")
path to desktop as text
表示当前用户的HFS桌面路径:
"Macintosh HD:Users:user:Desktop:"
关于dialog - 带有自定义图标的applescript显示对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47911943/