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

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
     * 
     */
    
    
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值