我希望我的程序能够显示一个弹框或者通知,里面展示我自己的文字。这个怎么实现呢?还有,是否可以制作一个带有多个按钮的弹框来设置一个变量?
类似于批处理中的:
echo msgbox""<a.vbs&a.vbs
我希望我的程序能够显示一个弹框或者通知,里面展示我自己的文字。这个怎么实现呢?还有,是否可以制作一个带有多个按钮的弹框来设置一个变量?
类似于批处理中的:
echo msgbox""<a.vbs&a.vbs
使用osascript
。例如:
osascript -e 'tell app "Finder" to display dialog "Hello World"'
将“Finder”替换为您想要的任何应用程序。请注意,如果该应用程序在后台运行,则对话框也会出现在后台。要始终显示在前台,请使用“系统事件”作为应用程序:
osascript -e 'tell app "System Events" to display dialog "Hello World"'
请访问Mac OS X Hints了解更多关于IT技术的内容。
使用此命令从终端触发通知中心通知。
osascript -e 'display notification "Lorem ipsum dolor sit amet" with title "Title"'
sudo
):gem install terminal-notifier
terminal-notifier -message "Hello, this is my message" -title "Message Title"
brew install terminal-notifier
也可以起作用。 - gklka使用AppleScript:
display notification "Notification text" with title "Notification Title" subtitle "Notification sub-title" sound name "Submarine"
使用终端/bash和osascript
:
osascript -e 'display notification "Notification text" with title "Notification Title" subtitle "Notification sub-title" sound name "Submarine"'
没有子标题或声音。
使用AppleScript:
display alert "Alert title" message "Your message text line here."
使用终端/bash和osascript
:
osascript -e 'display alert "Alert title" message "Your message text line here."'
在bash中添加一行代码以在警报行后播放声音:
afplay /System/Library/Sounds/Hero.aiff
在AppleScript中添加同一行,让shell脚本完成工作:
do shell script ("afplay /System/Library/Sounds/Hero.aiff")
macOS内置这里选择的声音列表。
从一篇关于终端和AppleScript通知的便利文章中改编而来。
a=$(osascript -e 'try
tell app "SystemUIServer"
set answer to text returned of (display dialog "" default answer "")
end
end
activate app (path to frontmost application as text)
answer' | tr '\r' ' ')
[[ -z "$a" ]] && exit
我的 15 美分。Mac 终端等的一行代码,只需将 MIN= 设置为任何值,并显示消息。
MIN=15 && for i in $(seq $(($MIN*60)) -1 1); do echo "$i, "; sleep 1; done; echo -e "\n\nMac Finder should show a popup" afplay /System/Library/Sounds/Funk.aiff; osascript -e 'tell app "Finder" to display dialog "Look away. Rest your eyes"'
sudo su
clear; echo "\n\nPreparing for a sleep when timers done \n"; MIN=60*2 && for i in $(seq $(($MIN*60)) -1 1); do printf "\r%02d:%02d:%02d" $((i/3600)) $(( (i/60)%60)) $((i%60)); sleep 1; done; echo "\n\n Time to sleep zzZZ"; afplay /System/Library/Sounds/Funk.aiff; osascript -e 'tell app "Finder" to display dialog "Time to sleep zzZZ"'; shutdown -h +1 -s
osascript -e 'display notification "你好,世界!"'
osascript -e 'display notification "你好,世界!" with title "这是标题"'
osascript -e 'display notification "你好,世界!" with title "问候" sound name "潜艇"'
osascript -e 'display notification "'"$TR_TORRENT_NAME 下载完成!"'" with title " ✔ Transmission-daemon"'
来源:https://code-maven.com/display-notification-from-the-mac-command-line
osascript -e 'display dialog "Hello!"'
- Alex Reds