Journler date dues as notifications

time ago i wrote a script to show journler date dues as Growl Grrrr… notifications.
But they doesn’t work. I don’t know why, but the problem must be little and with some tweaks these scripts could be useful for Journler-fans.

Maybe this script looks a bit clumpsy, but Growl isn’t so simple to script. Perhaps somebody knows a better method?
Anyway, i found irritating that Journler doesn’t show any alarm message until date dues turns out. So, here a script to simplify reminding.
Ops. i forgot to cite StefanK, some portions of this script are written by him.

Script 1) ->located in my Journler-Folder

--DueDate as GrowlNotification (shows due date entries of Journler as Growl notification with the help of launchctl) 
--Journler

tell application "Journler"
try
set my_item to item 1 of (get selected entries)
on error number the_error
if the_error is "-1728" then --if date due is not missing value then
  display dialog "Set the due date of your entry!" buttons "End"
else
  display dialog "Select a entry with due date" buttons "End"
end if
return 0
end try

set nm_of to name of my_item
set {the_txt, dueDate} to {(rich text of my_item), (date due of my_item)}
set dt_of to date due of my_item
set {t0, t1, t2, t3, t4} to {(minutes of dt_of), (hours of dt_of), (day of dt_of), (weekday of dt_of as number), (month of dt_of as number)}
end tell

set model_1 to (tab & tab & "<key>Minute</key>
<integer>" & t0 & "</integer>" & return & tab & tab & "<key>Hour</key>
<integer>" & t1 & "</integer>" & return & tab & tab & "<key>Day</key>
<integer>" & t2 & "</integer>" & return & tab & tab & "<key>Weekday</key>
<integer>" & t3 & "</integer>" & return & tab & tab & "<key>Month</key>
<integer>" & t4 & "</integer>" & return as text)

set compo_loc to ((path to scripts folder) & "Utility:Growl:Journler-Growl.scpt" as text)
set triggeredScriptLocation to POSIX path of (compo_loc as Unicode text)
set userLibraryPath to (path to library folder from user domain)

tell application "Finder"
try
make new folder at userLibraryPath with properties {name:"LaunchAgents"}
end try
try
make new folder at (userLibraryPath & "LaunchAgents:" as text) with properties {name:"Journler"}
end try
try
make new folder at ((path to scripts folder) & "Utility:Growl:" as text) with properties {name:"Journler ads"}
end try
end tell

set LaunchAgentsFolder to (userLibraryPath & "LaunchAgents:Journler:" as text)
set pListLabel to ("com." & nm_of & ".agent" as text)
set pListfile to ((LaunchAgentsFolder as Unicode text) & pListLabel & ".plist")

set PLIST_File to "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>Label</key>
<string>" & pListLabel & "</string>
<key>LowPriorityIO</key>
<true/>
<key>Program</key>
<string>/usr/bin/osascript</string>
<key>ProgramArguments</key>
<array>
<string>osascript</string>
<string>" & triggeredScriptLocation & "</string>
</array>
<key>StartCalendarInterval</key>
<dict>" & return & model_1 & tab & "</dict>
</dict>
</plist>" & return

try
set ff to open for access file pListfile with write permission
write PLIST_File to ff as «class utf8»
close access ff
set launchctlCmd to "launchctl load -w " & quoted form of POSIX path of pListfile
do shell script launchctlCmd
end try

my main(nm_of, the_txt, dt_of)

on main(nm_of, the_txt, dt_of)
set mmo_tg to ((path to scripts folder from user domain) & "Utility:Growl:Journler ads:" & nm_of & ".txt" as text)
try
open for access file mmo_tg with write permission
on error
close access file mmo_tg
return 0
end try
write the_txt to file mmo_tg
close access file mmo_tg
set mmo_tg to mmo_tg as alias
tell application "Finder" to set modification date of mmo_tg to dt_of
end main

Script 2)-> located in my Growl folder of Scripts folder

--JournlerAds
--journler

set cu_dt to current date
set {dy, mo, ho, mu} to {(day of cu_dt), (month of cu_dt as number), (hours of cu_dt), (minutes of cu_dt)}
set get_doc to {}
set pt_fl to ((path to scripts folder from user domain) & "Utility:Growl:Journler ads:" as text)
tell application "Finder" to repeat with i in alias pt_fl --check for multiple entries
set thec to modification date of i
set {v1, v2, v3, v4} to {(day of thec as number), (month of thec as number), (hours of thec), (minutes of thec)}
if v1 = dy and v2 = mo and v3 = ho and v4 = mu then
set get_doc to i
exit repeat
end if
end repeat
if get_doc is not {} then
set get_doc to get_doc as alias
else
return 0
end if

set th_nm to name of (info for of get_doc)
set the_txt to read get_doc
set nm_of to (characters 1 thru -5 of th_nm) as text
set cat_of to ""

tell application "GrowlHelperApp"
set the allNotificationsList to ¬
{cat_of, "Reclame"}

set the enabledNotificationsList to ¬
{cat_of}

register as application ¬
"Journler-Growl" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Journler"

notify with name ¬
cat_of title ¬
nm_of description ¬
cat_of & return & the_txt application name "Journler-Growl" sticky yes priority 3
end tell

do shell script "rm " & quoted form of POSIX path of get_doc