dialog - 带有自定义图标的applescript显示对话框

标签 dialog icons applescript display

有没有办法将自定义图标与 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.

意思是:参数必须是 aliasfile 说明符,而不是 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/

相关文章:

dialog - Testcafe - 无法关闭浏览器对话框

unity-game-engine - 禁用光探针图标

android - 菜单中的图标比应有的小

macos - 如何使用 AppleScript 或终端删除 PNG 文件的预览图标?

javascript - 如何在 JavaScript Automation 中获取最前面的 Safari 文档或选项卡?

java - JFace 对话框以编程方式最大化

linux - bash 脚本 : how to get item name on a radiolist using dialog

android - MapFragment 样式为 Dialog 导致 TextView 透明

c# - 制作一个图标闪烁的wpf应用程序

vim - 如何更新applescript以在iTerm3中的vim中打开txt文件