【问题标题】:Add an icon to pop-up in Terminal添加图标以在终端中弹出
【发布时间】:2017-05-31 16:48:32
【问题描述】:

基本上,我想在终端的弹出警报提示中添加一个图标。代码如下:

osascript -e 'tell app "System Events" to text returned of (display dialog "Enter Text: " default answer "")'

举个例子,当系统提示您输入密码窗口时,窗口中有一个锁定图标。谢谢!

【问题讨论】:

    标签: macos command-line terminal


    【解决方案1】:

    要将图标添加到 AppleScript 对话框,您可以使用:

    with icon file "path:to:icon.icns"
    

    路径是位置和文件名(图标可以是.png 等),所以你最终会得到:

    osascript -e 'tell app "System Events" to text returned of (display dialog "Enter Text: " default answer "" with icon file "path:to:icon.icns")'
    

    【讨论】:

    • 我尝试了以下操作:osascript -e 'tell app "System Events" to text returned of (display dialog "Enter Text: " default answer "" with icon file "~/Desktop/icon.icns")' 尽管它说:“文件文件 ~/Desktop/icon.icns 未找到”,但它不起作用,即使 icon.icns 在我的桌面上。 @l'l'l
    • 你需要使用Volume:Users:Username:Desktop:icon.icns形式的POSIX路径,或者使用类似的路径,因为它在你的桌面上with icon ((path to desktop as text) & "icon.icns") as alias
    • @natojato:你也可以使用with icon ((path to home folder as text) & "Desktop:icon.icns") as alias,从~/ 主目录开始,然后使用"directory:file" 指定路径的其余部分...
    • osascript -e 'tell app "System Events" to text returned of (display dialog "Hello World" default answer "" with icon ((~/Users/user) & "Desktop:icon.icns"))' 但它说“语法错误:预期的表达式,“)””
    • 你做错了——你不能在 AppleScript 中那样使用路径。如果您复制了我在两个 cmets 中放入的示例,它应该可以工作(如果您的文件名为 icon.icns 并且位于用户的 Desktop 上)。 (例如osascript -e 'tell app "System Events" to text returned of (display dialog "Enter Text: " default answer "" with icon ((path to home folder as text) & "Desktop:icon.icns") as alias )')。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-04
    • 1970-01-01
    • 1970-01-01
    • 2016-09-10
    • 2021-06-09
    • 1970-01-01
    相关资源
    最近更新 更多