您的位置:首页 > 其它

mac上推送自定义消息(右上角提示)

2015-04-01 13:42 281 查看
1、下载 http://download.s32cdn.com/21/202517/706564/Growl-1.2.2.dmg
2、然后利用applescript调用growl api,下面php例子中 调用 send_message()即可

function send_message($title , $content){
$as_content = create_applescript($title , $content);
file_put_contents(THIS_DIR.'/hmail/_applescript.script', $as_content);
exec('osascript '.THIS_DIR.'/hmail/_applescript.script');
}

function create_applescript($title , $content){
$application_name = '未读邮件提醒脚本';
return '
tell application "System Events"
set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
end tell

if isRunning then
tell application id "com.Growl.GrowlHelperApp"

set the allNotificationsList to ¬
{"The Notification"}

set the enabledNotificationsList to ¬
{"The Notification"}

register as application ¬
"'.$application_name.'" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Script Editor"

--       Send a Notification...
notify with name ¬
"The Notification" title ¬
"'.$title.'" description ¬
"'.$content.'" application name "'.$application_name.'"
end tell
end if
';

/*
*
*
tell application "System Events"
set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
end tell

if isRunning then
tell application id "com.Growl.GrowlHelperApp"
-- Make a list of all the notification types
-- that this script will ever send:
set the allNotificationsList to ¬
{"Test Notification", "Another Test Notification"}

-- Make a list of the notifications
-- that will be enabled by default.
-- Those not enabled by default can be enabled later
-- in the 'Applications' tab of the growl prefpane.
set the enabledNotificationsList to ¬
{"Test Notification"}

-- Register our script with growl.
-- You can optionally (as here) set a default icon
-- for this script's notifications.
register as application ¬
"Growl AppleScript Sample" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Script Editor"

--       Send a Notification...
notify with name ¬
"Test Notification" title ¬
"Test Notification" description ¬
"This is a test AppleScript notification." application name "Growl AppleScript Sample"

notify with name ¬
"Another Test Notification" title ¬
"Another Test Notification :) " description ¬
"Alas — you won't see me until you enable me..." application name "Growl AppleScript Sample"

end tell
end if
*
*/

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: