JSh*_*hoe 97 macos terminal alert applescript popup
我希望能够让我的程序显示警报,通知,显示我的自定义文本.这是怎么做到的?此外,是否可以使用几个按钮设置变量?
与批次类似:
echo msgbox""<a.vbs&a.vbs
Ann*_*nne 198
使用osascript
.例如:
osascript -e 'tell app "Finder" to display dialog "Hello World"'
Run Code Online (Sandbox Code Playgroud)
用您想要的任何应用程序替换"Finder".请注意,如果该应用程序是背景的,则对话框也将显示在后台.要始终显示在前台,请使用"系统事件"作为应用程序:
osascript -e 'tell app "System Events" to display dialog "Hello World"'
Run Code Online (Sandbox Code Playgroud)
阅读更多关于Mac OS X的提示.
Enr*_*sso 60
如果您使用的是具有Notification Center的任何Mac OS X版本,则可以使用terminal-notifier gem.首先安装它(您可能需要sudo
):
gem install terminal-notifier
Run Code Online (Sandbox Code Playgroud)
然后简单地说:
terminal-notifier -message "Hello, this is my message" -title "Message Title"
Run Code Online (Sandbox Code Playgroud)
另请参阅此OS X每日帖子.
Pra*_*ani 57
使用此命令从终端触发通知中心通知.
osascript -e 'display notification "Lorem ipsum dolor sit amet" with title "Title"'
Run Code Online (Sandbox Code Playgroud)
and*_*Oak 11
使用AppleScript:
display notification "Notification text" with title "Notification Title" subtitle "Notification sub-title" sound name "Submarine"
Run Code Online (Sandbox Code Playgroud)
使用终端/bash和osascript
:
osascript -e 'display notification "Notification text" with title "Notification Title" subtitle "Notification sub-title" sound name "Submarine"'
Run Code Online (Sandbox Code Playgroud)
不采用副标题,也不采用强硬的声音。
使用AppleScript:
display alert "Alert title" message "Your message text line here."
Run Code Online (Sandbox Code Playgroud)
使用终端/bash和osascript
:
osascript -e 'display alert "Alert title" message "Your message text line here."'
Run Code Online (Sandbox Code Playgroud)
在bash 中添加一行用于在警报行之后播放声音:
afplay /System/Library/Sounds/Hero.aiff
Run Code Online (Sandbox Code Playgroud)
在AppleScript 中添加相同的行,让shell 脚本完成工作:
do shell script ("afplay /System/Library/Sounds/Hero.aiff")
Run Code Online (Sandbox Code Playgroud)
转述自一篇关于终端和 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
Run Code Online (Sandbox Code Playgroud)
如果您告诉系统事件显示对话框,如果之前没有运行,则会有一个小延迟.
有关显示对话框的文档,请在AppleScript编辑器中打开标准添加词典,或参阅AppleScript语言指南.
还有我的 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"'
Run Code Online (Sandbox Code Playgroud)
组合更多命令的灵感奖励示例;这也会让 mac 在收到消息后进入待机睡眠状态:) 然后需要 sudo 登录,乘以两个小时的 60*2 也是如此
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
Run Code Online (Sandbox Code Playgroud)
osascript -e \'display notification "hello world!"\'
osascript -e \'display notification "hello world!" with title "This is the title"\'
osascript -e \'display notification "hello world!" with title "Greeting" sound name "Submarine"\'
osascript -e \'display notification "\'"$TR_TORRENT_NAME has finished downloading!"\'" with title " \xe2\x9c\x94 Transmission-daemon"\'
学分: https: //code-maven.com/display-notification-from-the-mac-command-line
\n 归档时间: |
|
查看次数: |
107597 次 |
最近记录: |