sh用于封装发送用户通知的shell脚本(代码片段)

author author     2022-12-21     111

关键词:

#!/bin/bash
# sendusernotification.sh
# Created by Alexander Celeste for Tenseg in March 2016
# This script can be used to send user notifications to Notification Center, regularly just to OS X, but also to the Prowl iOS app if the Mac is idle
# It can be used in long-running scripts to notify of completion, and in scripts that run via launchd to notify of files being added to folders, or really any use you can dream up
# Dependencies:
#	* terminal-notifier: https://github.com/julienXX/terminal-notifier
#	* prowl.pl: https://www.prowlapp.com/static/prowl.pl

# get inputs
Title="$1"
Message="$2"
Identifier="$3"
if [ -z "$Identifier" ]; then
	Identifier="com.apple.Terminal"
fi

# send to OS X Notification Center
# uses https://github.com/julienXX/terminal-notifier
/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier -title "$Title" -message "$Message"  -sender "$Identifier"

# send to iOS Notification Center if the Mac has been idle for a minute or longer, there is both a Prowl and a IFTTT method below, pick the one you desire most
# both methods rely on you saving the API key used for the relevant service to a Secure Note in Keychain Access
IdleTime=$(/usr/bin/printf "%.0f" $(/usr/sbin/ioreg -c IOHIDSystem | /usr/bin/awk '/HIDIdleTime/ print $NF/1000000000; exit'))
if [ $IdleTime -ge 60 ]; then
	Path=$(/usr/bin/mdfind kMDItemCFBundleIdentifier = "$Identifier")
	b=$(/usr/bin/basename $Path)
	Application=$(/bin/echo $b | /usr/bin/cut -f 1 -d '.')
	# Prowl method, uses https://www.prowlapp.com/static/prowl.pl
	ApiKey=$(/usr/bin/security find-generic-password -g -s "prowlapikey" 2>&1 1>/dev/null | /usr/bin/perl -pe '($_) = /"(.+)"/; s/\\012/\n/g' | perl -MXML::LibXML -e 'print XML::LibXML->new()->parse_file("-")->findvalue(q(//string[preceding-sibling::key[1] = "NOTE"]))')
	/usr/local/bin/prowl.pl -apikey="$ApiKey" -application="$Application" -event="$Title" -notification="$Message"
	# IFTTT method
	Key=$(/usr/bin/security find-generic-password -g -s "iftttmakerkey" 2>&1 1>/dev/null | /usr/bin/perl -pe '($_) = /"(.+)"/; s/\\012/\n/g' | perl -MXML::LibXML -e 'print XML::LibXML->new()->parse_file("-")->findvalue(q(//string[preceding-sibling::key[1] = "NOTE"]))')
	/usr/bin/curl -H "Content-type: application/json" -X POST -d ' "value1":"'$Application'","value2":"'$Title'","value3":"'$Message'"' https://maker.ifttt.com/trigger/mac_notification_recieved/with/key/$Key
fi

sh用于查找docker图像后代的shell脚本(代码片段)

查看详情

sh用于运行npminstall和bowerupdate的shell脚本(代码片段)

查看详情

sh用于向yaml文件添加定义的shell脚本(代码片段)

查看详情

sh用于从google云端硬盘下载文件的shell脚本。(代码片段)

查看详情

sh实验!用于为alce配置envirorment的shell脚本(代码片段)

查看详情

sh用于安装docker的用户数据脚本(代码片段)

查看详情

sh用于备份组织的所有github存储库的shell脚本(代码片段)

查看详情

sh用于将图像上传到imgur.com的shell脚本(代码片段)

查看详情

sh用于tar的shell脚本解压缩选项示例字符串(代码片段)

查看详情

sh用于tar的shell脚本解压缩选项示例字符串(代码片段)

查看详情

sh用于将项添加到yaml术语列表的shell脚本(代码片段)

查看详情

sh用于显示包含每个用户的crontab的脚本(代码片段)

查看详情

sh用于选择最快的freebsd-update镜像的shell脚本(代码片段)

查看详情

sh用于将.css.scss重命名为.scss的shell脚本(代码片段)

查看详情

sh用于在ubuntu16系统上设置laravelproduction环境的shell脚本。(代码片段)

查看详情

linux系统shell脚本之向指定终端发送消息(代码片段)

Linux系统shell脚本之向指定终端发送消息一、脚本要求二、脚本内容三、编辑消息内容四、发送消息到终端五、到登录用户终端查看消息一、脚本要求向正在登录的admin用户终端界面发送一条测试信息二、脚本内容[root@masteruser]... 查看详情

sh用于在iiit-b上测试互联网连接的shell脚本(代码片段)

查看详情

sh用于备份和从awss3删除旧备份的简单脚本shell(代码片段)

查看详情