Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AppleScript Deleting Calendar

Hello everyone,


I have a quick question regarding AppleScript.


I got multiple calendars "Untitled 1" "Untitled 2" etc. this goes up to "Untitled 325".


I wanted to run a small Apple Script, which would remove those for me automatically.


For that I wrote this one:


tell application "iCal" to activate
repeat
          tell application "iCal"
                    if exists calendar "Untitled" then
                              delete calendar "Untitled"
                    else
                              delete calendar "Untitled"
                    end if
          end tell
end repeat


The problem is, as you can see that it really just search for "Untitled" calendar names, it does not search for the others and won't delete them either. I tried then several way for example using a * after Untitled or a empty space then a * etc. I have also googled for a command which could help me but I was not successful.


It would be great, If anyone could tell me how to tell this Script to delete any calendar which start with "Untitled".


I'm looking forward for feedback! Thanks in advance.


iPhoneRockets

Posted on Aug 3, 2011 11:16 AM

Reply
Question marked as Best reply

Posted on Aug 3, 2011 11:33 AM

I haven't tried this, but I'd expect something like this to work:


tell application "iCal"

delete (every calendar whose name begins with "Untitled")

end tell

7 replies

Aug 3, 2011 12:41 PM in response to iPhoneRockets

Or (less elegant and untested. When will we get AppleScript for iPad?)



tell application "iCal"

set cal_count to (count calendars)

repeat with x from 1 to cal_count

set cal_name to "Untitled " & (x as string)

try

delete calendar cal_name

end try

end repeat

end tell


Careful - your script, if you got it going, would loop infinitely. You need to set an upper limit on the number of loops. Here, it's the same as the number of calendars.

Aug 3, 2011 1:59 PM in response to Camelot

Hi there,


I have updated a bit to have a kind of GUI for it. Very very simple one. Is it possible that I can use the calendar name as a variable slot so that I can type over the GUI the name of the calendar ?


set question to display dialog "Cleaning It" buttons {"Leave me alone!", "Delete every calendar begins with Untitled"} default button 2

set answer to button returned of question


if answer is equal to "Let's go there!" then

tell application "iCal"

delete (every calendar whose name begins with "Untitled")

end tell

end if



Thanks again

Aug 3, 2011 2:41 PM in response to iPhoneRockets

I updated It but Its not working yet. Im happy for any help.


property this_text : "Afraid to type?"

tell application "iCal"


activate


display dialog "Enter some text" default answer "" buttons {"Cancel", "Continue"} default button 2

set the this_text to text returned of the result

set this_message to delete (every calendar whose name begins with {content:this_text, visible:true})



end tell


Thanks again

Aug 3, 2011 2:42 PM in response to iPhoneRockets

This statement makes no sense:


delete calendar begins with {content:this_text,visible:true}


How can a calendar's name begin with a list and a property? Can't happen.


What I think you're aiming for is all calendars who match the name and are also visible - these are two separate conditions wheras you've combined them into one - or, at least, you've tried to.


A larger problem, though, is that visible isn't a standard property of a calendar - from what I can see there's no indicator to tell whether a calendar is visble or not.

Aug 3, 2011 2:49 PM in response to Camelot

I think I got it with:


property this_text : "Afraid to type?"

tell application "iCal"


activate


display dialog "Enter some text" default answer "" buttons {"Cancel", "Continue"} default button 2

set the this_text to text returned of the result

set this_message to delete (every calendar whose name begins with {this_text})



end tell


at least it is working! Thanks CAmelot.

AppleScript Deleting Calendar

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.