mailto:在 Ubuntu 中使用通知消息打开 google chrome
我正在编写一个小脚本来打开 google chrome 小应用程序窗口中网页的 mailto 链接:
到目前为止,我有这个:
#!/bin/sh
notify-send "Opening Gmail" "`echo $1`" -i /usr/local/share/icons/hicolor/48x48/apps/google-chrome.png -t 5000
google-chrome -app="https://mail.google.com/mail/?extsrc=mailto&url=`echo $1`"
效果很好 - 但是我想将电子邮件收件人添加到通知中 - 类似这样 - 但我需要一个正则表达式从 mailto 链接获取电子邮件 - 它可能包含主题等..
#!/bin/sh
$str = preg_replace('#<a.+?href="mailto:(.*?)".+?</a>#', "$1", $str);
notify-send "Opening Gmail" "`echo $str`" -i /usr/local/share/icons/hicolor/48x48/apps/google-chrome.png -t 5000
google-chrome -app="https://mail.google.com/mail/?extsrc=mailto&url=`echo $1`"
这不起作用..
有什么想法吗?
更新:这是工作代码:
#!/bin/sh
str=$(echo $1|sed 's/.*mailto:\([^?]*\)?.*/\1/')
notify-send "Opening Gmail" "to: `echo $str`" -i /usr/local/share/icons/hicolor/48x48/apps/google-chrome.png -t 5000
google-chrome -app="https://mail.google.com/mail/?extsrc=mailto&url=`echo $1`"
I'm writing a small script to open mailto links from webpages in google chrome small app window:
so far I have this:
#!/bin/sh
notify-send "Opening Gmail" "`echo $1`" -i /usr/local/share/icons/hicolor/48x48/apps/google-chrome.png -t 5000
google-chrome -app="https://mail.google.com/mail/?extsrc=mailto&url=`echo $1`"
which works nice - however I'd like to add the email recipient to the notification - something like this - but I need a regex to get the email from the mailto link - which might contain subjects and such..
#!/bin/sh
$str = preg_replace('#<a.+?href="mailto:(.*?)".+?</a>#', "$1", $str);
notify-send "Opening Gmail" "`echo $str`" -i /usr/local/share/icons/hicolor/48x48/apps/google-chrome.png -t 5000
google-chrome -app="https://mail.google.com/mail/?extsrc=mailto&url=`echo $1`"
this does not work..
any ideas?
UPDATE: here's the working code:
#!/bin/sh
str=$(echo $1|sed 's/.*mailto:\([^?]*\)?.*/\1/')
notify-send "Opening Gmail" "to: `echo $str`" -i /usr/local/share/icons/hicolor/48x48/apps/google-chrome.png -t 5000
google-chrome -app="https://mail.google.com/mail/?extsrc=mailto&url=`echo $1`"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你这样写,它就不是 shell:)
你能提供使用正则表达式的示例字符串吗?基本上它将是 sed 调用,它将删除除地址之外的所有内容。尽管根据 RFC 的邮件地址可能相当复杂,因此简单的方法在大多数情况下都有效,但并非每次都有效。
尝试从类似的东西开始
所以你可能想像这样使用它:
If you write it like this, it's not shell:)
Can you provide the sample string to use regex unto? Basically it will be sed invocation, that shall cut everything but the address. Although the mail address according to the RFC can be quite complicated, so the simple approach will work in most of the cases, but not every time.
Try to start from something like
So you might want to use it like this:
伟大的!我得到了你的脚本并做了一些更改以更好地工作,看:
Great! I got your script and made some change to work better, look: