使用 osascript -e “显示通知"时更改通知图标 [英] Change icon of notification when using osascript -e "display notification"

查看:49
本文介绍了使用 osascript -e “显示通知"时更改通知图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 emacs 编写一个插件,该插件使用 OS X 的本机通知显示来显示通知.

I'm trying to write a plugin for emacs that displays a notification using OS X's native notification display.

我遇到了 terminal-notifier ,它可以工作,但它是一个依赖项,不适用于每台 Mac.另外,应该让用户知道他们需要安装软件包.

I've run into terminal-notifier which works, but it's a dependency that doesn't work on every mac. Plus the user should be made aware that they need to install the package.

我想做的是调用一个进程 osascript -e 并让它显示通知.问题是,更改其图标的唯一方法是从外部包中.有什么办法可以让 osascript -e 显示我想要的.

What I want to do is call a process osascript -e and make it display the notification. The problem is, the only way to change its icon is from an external bundle. Is there any way to make osascript -e display what I want.

开始 sudo osascript 似乎这样做,但它似乎是糟糕的设计,我还需要找到一种方法来每次都传递 root 密码.

starting sudo osascript seems to do that, but it seems to be bad design and I also need to find a way to pass the root password every single time.

推荐答案

你不能.这根本不是暴露给 AppleScript 的 macOS 功能.

You cannot. This is simply not a macOS feature exposed to AppleScript.

如果您需要自定义图标,请考虑使用弹出对话框"而不是通知中心弹出窗口.使用超时和按钮,您可以重新创建大部分功能,但无法实现集成和美观.

If you need a custom icon, consider using a pop-up "dialog" rather than a Notification Center pop-up. With timeouts and buttons you can recreate much of the functionality, though not the integration nor aesthetics.

在显示对话框"中,如果您希望使用标准图标:0、1 或 2(停止、注释或警告),也许不要让 osascript 作为显示图标的程序.查找器,例如:

In `display dialog', if you wish to use the standard icons: 0, 1, or 2 (stop, note, or caution), perhaps don't have osascript be the program that displays the icon. Finder, for example:

osascript -e '告诉应用程序Finder"' -e 'activate' -e '显示对话框这是笔记图标."带有图标注释' -e '结束告诉'

或者没有 tell 应用程序...,您可以通过直接引用来使用您选择的图标,例如终端应用程序的图标:

or without the tell application… you may use an icon of your choice by referencing it directly, e.g. the Terminal app's icon:

osascript -e '显示对话框终端图标",图标别名为Macintosh HD:Applications:Utilities:Terminal.app:Contents:Resources:Terminal.icns"'

我不确定您的意思,更改其图标的唯一方法是从外部包中.有什么方法可以使 osascript -e 显示我想要的内容." 你到底想要什么?你尝试过什么?

I'm not sure what you mean by, "the only way to change its icon is from an external bundle. Is there any way to make osascript -e display what I want."  What, precisely, do you want? What have you tried?

这是 显示对话框 Apple 文档中的部分.

Here's the display dialog section from Apple's documentation.

这篇关于使用 osascript -e “显示通知"时更改通知图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆