It works great on the first run when the application is not running. But if the application is running when my script is run, I get an error:
error “Notifications Scripting got an error: AppleEvent handler failed.” number -10000
on line:
set event handlers script path to (path to me)
with ‘event handlers script path’ highlighted. As a workaround, I added a quit Notifications Scripting at the beginning of the script:
global title_text, cur_date, sub_title, num_mins, snooze_mins, msg_text, the_sound
set title_text to "Wake up!"
set cur_date to (current date)
set sub_title to date string of cur_date
set num_mins to 1
set msg_text to "snooze: " & num_mins & " min."
set snooze_secs to 15 --num_mins * minutes
set the_sound to "Quack"
(*
-- added this, otherwise error on next run if NotificationsScripting still running
tell application "Notifications Scripting" to quit
delay 1
*)
--
tell application "Notifications Scripting"
-- required for calling the user notification event handlers
-- handlers can be in a different script file.
set event handlers script path to (path to me)
-- 'user info' supported data types are text, integer, real, boolean, date, alias, file and POSIX file.
set dict to {theName:"Notifications Scripting", theVersion:"1.0", theScript:event handlers script path}
-- Create a notification. Only the title is required at minimum.
-- Use "Default" for the default sound played by the user notification center.
display notification title_text subtitle sub_title message msg_text action button "Snooze" other button "OK" sound name the_sound delivery date (cur_date + snooze_secs) user info dict
end tell
using terms from application "Notifications Scripting"
-- This handler is called when a notification was delivered.
-- All parameters are optionnals.
on notification delivered title aTitle subtitle aSubTitle message aMessage actual delivery date aDeliveryDate user info aDict
(*
tell application "Finder"
display dialog aTitle & return & aDeliveryDate & return & (theScript of aDict) as text
end tell
*)
beep 3
say "greeting is delivered"
end notification delivered
-- This handler is called when a notification was activated.
-- All parameters are optionnals.
on notification activated title aTitle subtitle aSubTitle message aMessage delivered date aDeliveryDate activation type aType user info aDict
(*
-- activation type describe how the user notification was activated :
-- 1 : the user clicked on the contents of the notification alert
-- 2 : the user clicked on the action button of the notification alert
tell application "Finder"
display dialog aTitle & return & aSubTitle & return & aMessage & return & aType
end tell
*)
say "greeting was recieved"
end notification activated
end using terms from
It works great when I uncomment the quit application “Notifications Scripting” line. It’s funny, but reading the reviews on this app, none mentions this error. I reinstalled it several times, but no go. Can someone confirm this?
That doesn’t work. It’s hard to tell what is going wrong with this app. Seems like it can’t read or set the handler ‘event handlers script path’ when it’s running. I tried to email the developer, but there’s something wrong with the address in the mailto.
global title_text1, title_text2, cur_date, sub_title, num_mins, snooze_mins, msg_text, the_sound
set title_text1 to "Wake up!"
set title_text2 to "Snooze"
set cur_date to (current date)
set sub_title to cur_date as string
set num_mins to 1
set msg_text to "snooze: " & num_mins & " min."
set snooze_secs to 20 -- num_mins * minutes
set the_sound to "Quack"
-- added this workaround for timeout error
tell application "Notifications Scripting" to quit
delay 1
--
-- remaining bug:
-- if user closes notification window before another window should open,
-- it doesn't open, but the notification delivered handler still runs
-- new rule: display once, but more than one display may be used
tell application "Notifications Scripting"
-- required for calling the user notification event handlers
-- handlers can be in a different script file.
-- set event handlers script path to my (path to me)
set event handlers script path to (path to me)
-- 'user info' supported data types are text, integer, real, boolean, date, alias, file and POSIX file.
set dict to {theName:"Notifications Scripting", theVersion:"1.0", theScript:event handlers script path}
-- Create a notification. Only the title is required at minimum.
-- Use "Default" for the default sound played by the user notification center.
display notification title_text1 subtitle sub_title message msg_text action button "Snooze" other button "OK" sound name the_sound delivery date (cur_date + snooze_secs) user info dict
display notification title_text2 subtitle sub_title message msg_text action button "Snooze" other button "OK" sound name the_sound delivery date (cur_date + snooze_secs) user info dict
return
end tell
using terms from application "Notifications Scripting"
-- This handler is called when a notification was delivered.
-- All parameters are optionnals.
on notification delivered title aTitle subtitle aSubTitle message aMessage actual delivery date aDeliveryDate user info aDict
(*
tell application "Finder"
display dialog aTitle & return & aDeliveryDate & return & (theScript of aDict) as text
end tell
*)
say "notification is delivered"
return
end notification delivered
-- This handler is called when a notification was activated.
-- All parameters are optionnals.
on notification activated title aTitle subtitle aSubTitle message aMessage delivered date aDeliveryDate activation type aType user info aDict
(*
tell application "Finder"
-- activation type describe how the user notification was activated :
-- 1 : the user clicked on the contents of the notification alert
-- 2 : the user clicked on the action button of the notification alert
display dialog aTitle & return & "activation type " & aType as text
end tell
*)
say "notification was recieved"
return
end notification activated
end using terms from
It works ok as long as the user doesn’t close on alert before another scheduled alert is delivered.