I’m trying to write a line that tests for a certain kind of alarm in an iCal event. I’m still new to Applescript, so I’m trying to find the right grammar for the line, and I’m hoping someone here can help me…
In English, I’m basically trying to say “…every event which has a Run Script alarm that runs TheScript.scpt” I’ve had some success with similar lines (e.g. [whose description is “test”] and [whose start date is less than or equal to (current date)]), but I can’t quite get this to work. I think it’s something along the lines of [whose run script alarm is TheScript.scpt], but I can’t find the right grammar.
Till recently, I knew nothing about how to use applescript dictionary and I was just like you making random guesses till one great soul in this forum suggested me to use Script Debugger to understand dictionaries. I suggest you to try it as well.
In the iCal dictionary, there is an open file alarm, display alarm, mail alarm and sound alarm. There is no “run script” alarm.
Now replace the word “Calendar” in the script below with the name of an existing Calendar in your iCal which has todos with run script alarms.
set thelist to {}
tell application "iCal"
tell calendar "Calendar"
set thetodos to every todo
repeat with aitem in thetodos
set thefilepath to filepath of open file alarm of aitem
if thefilepath is not {} then
set thefilepath to thefilepath as text
if thefilepath ends with ".scpt" then set end of thelist to summary of aitem
end if
end repeat
end tell
end tell
thelist
i have assumed that you run applescripts and not any other scripts like javascripts, or bash scripts. If the assumption does not hold true, you may have to make changes in the script. This script also assumes that you don’t have “Open file” alarms set to open applescripts. If that is the case, then you have a problem which may require some more work.
(This is not the ideal script, you can wait for someone else to give a better one)