Help - Applescript to Delete Calendar

I need to find an applescript or automator sequence to delete a calendar from iCal.
The calendar to be deleted would always have the same name.
Could use some help here.
Thanks in advance.

John,
Really appreciate your help. This is a nice script you have done.
I put the delete / create up front. I find that whatever name I use, the new calendar created is "untitled" so I am just using that.
Anyway, I just want SourceCal to be "untitled" and
myfile to be Calendar Export.txt from my documents folder
Thanks.
Rex
tell application "iCal" to delete calendar "untitled"
tell application "iCal" to create calendar "untitled"
tell application "iCal"
set sourceCal to first calendar whose name is (item 1 of (choose from list (name of (every calendar) as list) with prompt "Choose calendar to add events to."))
set myFile to choose file with prompt "Where is the exported Now Up To Date file?"
end tell
set myEvents to paragraphs of (read myFile)
set myNow to current date
repeat with thisEvent in myEvents
set {myTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {tab}}
set eventDetails to text items of thisEvent
set AppleScript's text item delimiters to myTIDs
if (count of eventDetails) is greater than 1 then
set anEvent to false
set allDay to false
if item 2 of eventDetails is not equal to "" then
set thisStart to date (item 1 of eventDetails & " " & item 2 of eventDetails)
set thisEnd to date (item 1 of eventDetails & " " & item 3 of eventDetails)
set anEvent to true
else
set thisStart to date (item 1 of eventDetails)
if item 6 of eventDetails contains "All Day" or item 6 of eventDetails contains "Banner" then
set thisEnd to (date (item 1 of eventDetails)) + 1 * days
set allDay to true
set anEvent to true
end if
end if
set mySummary to (item 4 of eventDetails)
set {myTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {ASCII character 11}}
set (item 5 of eventDetails) to text items of (item 5 of eventDetails)
set AppleScript's text item delimiters to {return}
set (item 5 of eventDetails) to (item 5 of eventDetails) as text
set AppleScript's text item delimiters to myTIDs
set myDescription to "CATEGORY: " & (item 8 of eventDetails) & return & "TYPE: " & (item 6 of eventDetails) & return & "PRIORITY: " & (item 7 of eventDetails) & return & (item 5 of eventDetails)
set doneFlag to false
if (item 10 of eventDetails) is equal to "Done" then set doneFlag to true
tell application "iCal"
if anEvent is true then
set newEvent to make new event at the end of events of sourceCal with properties {summary:mySummary, description:myDescription, start date:thisStart, end date:thisEnd}
if allDay is true then
set allday event of newEvent to true
else
set end date of newEvent to thisEnd
end if
else
set newToDo to make new todo at the end of todos of sourceCal with properties {summary:mySummary, description:myDescription, due date:thisStart}
if doneFlag is true then
set completion date of newToDo to myNow
end if
end if
end tell
end if
end repeat
tell application "iCal" to display dialog "events added in " & (current date) - myNow & " seconds."

Similar Messages

  • Help recover a deleted calendar

    Deleted a calendar called "Master" in iCal because it was not syncing with Outlook properly.  Now it removed all entries from Outlook and I can't recover any files.  Can anyone help?  Unfortunately I can't click on "undo" as I made additional clicks...

    I just took from Time Machine the old version back

  • Help - AppleScript to delete empty folders

    I have been trying to create an AppleScript that will let me clean directories of empty folders. I have scoured the web and developed the following script. It doesn't work. I have a simpler script but it requires that I enter my admin password everytime that a folder is identified to delete. I'm trying to develop something that only requires me to enter the admin password once. Can someone help me identify the problem with this script?
    on killEmpty(fol)
      tell application "Finder"
      repeat with f in (get fol's folders)
      my killEmpty(f)
      end repeat
      if (count items of fol) is 0 then do shell script "rmdir" with administrator privileges
      end tell
    end killEmpty
    tell application "Finder"
      repeat with f in (get folders of window 1)
      my killEmpty(f)
      end repeat
    endtell

    Hi,
    If you need an administrator's password, use a command in a do shell script to find and delete all empty folders, like this script:
    tell application "Finder" to set tDir to quoted form of POSIX path of the ((target of Finder window 1) as string)
    set pScript to quoted form of "from os import walk; from sys import argv; from shutil import rmtree; import glob
    for dirpath, _, _ in walk(argv[1], topdown=False):
        if not (glob.glob(dirpath + '/*')): rmtree(dirpath)"
    do shell script "/usr/bin/python -c " & pScript & " " & tDir with administrator privileges

  • Help - trouble editing & deleting calendar events

    I no longer have the ability to edit and/or delete recurring calendar events, or in some cases, stand alone events.  There is NO edit button to  be found on several, but not all, of my calendar events.  Therefore when I need to change a time I wind up with 3 calendar events sitting on top of each other as I am unable to edit.  I have checked the settings, my icloud, etc.  HELP!!!!  I have an iphone 5 operating iOS 7.0.4

    Clear BB data:
    http://btsc.webapps.blackberry.com/btsc/microsites​/search.do?cmd=displayKC&docType=kc&externalId=KB1​...
    You can also take a look at
    http://btsc.webapps.blackberry.com/btsc/search.do?​cmd=displayKC&docType=kc&externalId=KB04950&sliceI​...
    Please click the Thumbs Up icon if this comment has helped you!
    If your issue is resolved, please click the solution button on the resolution!
    Every BlackBerry should have BlackBerry Protect, get it now! | Follow me on Twitter | Bring Back BBM Music!

  • 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

    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

  • Help! I've accidentally deleted calendars from iCloud.

    I've accidentally deleted calendars from iCloud. Any help?

    Hi there Adam.Benoy,
    You may find the information in the article below helpful.
    Download past purchases
    http://support.apple.com/kb/ht2519
    -Griff W. 

  • Help - I mistakenly deleted a calendar project in iPhoto 11?

    How do I restore a mistakenly deleted calendar project to iPhoto 11? I have a full SuperDuper backup that shows the project when I'm booted into the backup.
    Thanks for any tips!

    Boot to the clone and follow Old Toad's directions for archiving a book (same for any keepsake) and copy the new archive library back to your main drive and use it - you can not "extract" a keepsake and more it - you must move
    the entire library
    Or if there are no new photos in the clone library just move it back to the main system - if there are some you could export the new photos, move the cloned library back and import the new photos again from the export or the source if it is available
    LN

  • I have DELETED calendars showing in my iTunes Sync Calendars list!?

    iMac late 2009
    OSx 10.10.2
    iPhone 6 Plus
    iOS 8.1.3
    Completely Up to Date!
    no clouds involved, no calendar subscriptions.
    I have had a major problem with my Calendar's calendars, which I have completely repaired using Calendar.  During that process, I had to rename a number of calendars in order to keep track of what I was doing - an intermediate diagnostic step.  Once I'd gotten everything right, exported all the "good" calendars to .ics files, and deleted ALL CALENDARS - both the good ones and the intermediately named ones -  then imported the .ics files back into Calendar... leaving me with ONE FULL SET OF CLEAN CALENDAR data.  When I open Calendars on my mac, I see 33 calendars listed on the left side of the window.
    My problem now that I'm ready to put my calendars back onto my phone, is that my Calendars Library (library/calendars) still has many of the intermediate calendar files (that have NOT been DELETED) and in iTunes, the list of Calendars includes all these same intermediate calendars, as well as the new calendars that I want to transfer to my phone.  I would prefer to "select" "ALL CALENDARS" but I can't do that until I can remove the calendars that were supposed to be deleted/removed in the first place.  In other words, I have 33 good, clean Calendars, but there are 71 Calendars in my Calendar Library.
    What are the correct steps to remove the Library/Calendars folder so that the iTunes "Sync Calendars" list only shows the 33 good calendars, and not the 38 unwanted (deleted) calendars.
    What do I have to do to finish the job?

    I have/had the same problem. I tried deleting all the "Library" "Calendar" preference files I could find and like others nothing worked. Like others they would just recreate themselves.
    BUT, I did find the solution. Not sure which part worked, but this is what I did.
    I quit all the apps, Calendar, and iTunes.
    I went into the folder pointed to by job-seeker above:
                   <user>
                   Library
                   Containers
                   com.aple.CalendarAgent
                   Data
                   Library
                   Calendars
    Manually went through each cached calendar folder and looked in the info.plist for the calendar title listed below "<key>Title</key>" and deleted the parent folders of no longer existent calendars.
    Then find an app called "Reminders", open it and you will find all the deleted calendars that you have deleted over the years, they seem to get cached in it, delete them and quit.
    Relaunch iTunes and find the deleted calendars in question are gone.
    I think you could skip all the above and just try deleting the old calendars from this Reminder app and it may work, but the above is what I did when it worked for me and I do not want to recreate the problem just to verify my theory. ;-)
    Hope this helps,
    Michael

  • I can't delete calendars from iCal, they re-appear in a few moments. Also I can't add new entries. I have a backup on another  Mac which is working properly.

    For the last 2 weeks iCal has not let me update or delete calendars. It continues to remind me about events in the past (about 10 days ago).
    Also, Safari is not recording history, apart from today the last entry is 2 weeks ago.
    Time and date is working OK.
    All software is up-to-date.

    My problem is fixed now, thank you. It was caused by my changing the Boot Camp partition's 'RAID1' to 'RAID0'. If I hadn't done that, Boot Camp would still have been able to 'restore' back to the one partition. It was fixed with the help of Applecare by using a terminal and typing a command to erase the IP of the Macintosh disk (not the volume) as well as the IP of the Bootcamp partition (if I remember correctly), but then I had to restore the OS and all my applications and data etc which I had previously backed up using Time Machine. I haven't taken note of the exact command terminology used. It would be wise to speak to Applecare about this if possible.
    Two words of warning, 1. According to the cause of this problem, it might be wise, after reinstalling the ops system to reinstall all extra applications one by one, manually, in case a similar problem arises again. Then manually copy back all data. Or the Mac user could use the Time Machine backup and then uninstall all the added apps then re-install them one by one manually. 2. Beware as after all this the user might not have the 'Recovery partition'. There is a small recovery partition (a few 100 Mb is size) which comes with all later Macs. After all this is done this tiny partition might not be there anymore and the user might have to re-install Mavericks again to get it back, or just install the upcoming update of Mavericks due in a month or so.

  • Is there any way to restore deleted calendars back onto my laptop from my iPhone.

    I recently installed Maverick on my laptop and have been having trouble syncing my iphone calendars with my laptop calendars, like I used to.
    Like an idiot, and without any research, I joined iCloud thinking I could sync calendars this way. I didn't realize that it deleted my calendars off my laptop in creating my iCloud calendars. The syncing with my iphone still didn't work, and so again, like an idiot and without research, I deleted my iCloud account ot discover that all my calendars on my laptop are now gone.
    My iphone still has the calendars on it, (albeit old and out of date), so is there a way to restore the deleted calendars back to my laptop from my iphone or from the backup on my laptop.?
    Running Maverick on laptop and iTunes 11.1.3. iPhone is an older 3gs but fully updated running 6.1.3
    Please help.
    Thanks!

    Triple-click anywhere in the line below on this page to select it, then copy it to the Clipboard by pressing the key combination command-C:
    ~/Library/Safari
    Quit Safari.
    Select
              Go ▹ Go to Folder
    from the Finder menu bar. Paste into the text box that opens by pressing command-V, then press return.
    A folder window should open. Restore the file named "History.plist" in that folder from a backup that predates the unwanted changes.

  • I have DELETED  calendars showing in my "Sync Calendars" list!?

    Sorry,  neglected to include that this additional information:
    I am not using any clouds
    I do not have any calendar subscriptions
    Thank you.

    I have/had the same problem. I tried deleting all the "Library" "Calendar" preference files I could find and like others nothing worked. Like others they would just recreate themselves.
    BUT, I did find the solution. Not sure which part worked, but this is what I did.
    I quit all the apps, Calendar, and iTunes.
    I went into the folder pointed to by job-seeker above:
                   <user>
                   Library
                   Containers
                   com.aple.CalendarAgent
                   Data
                   Library
                   Calendars
    Manually went through each cached calendar folder and looked in the info.plist for the calendar title listed below "<key>Title</key>" and deleted the parent folders of no longer existent calendars.
    Then find an app called "Reminders", open it and you will find all the deleted calendars that you have deleted over the years, they seem to get cached in it, delete them and quit.
    Relaunch iTunes and find the deleted calendars in question are gone.
    I think you could skip all the above and just try deleting the old calendars from this Reminder app and it may work, but the above is what I did when it worked for me and I do not want to recreate the problem just to verify my theory. ;-)
    Hope this helps,
    Michael

  • How do i permanently delete calendar on my mac

    I deleted all the calendars on my mac, however they continue to appear in Itunes when i sync my iphone 4 -- all icloud calendars have also been deleted.
    If i create a new calendar it does not appear on the list of calendars available to sync, but somehow the deleted calendars are still syncing with my iphone 4.   even though all those events were deleted from ical when i deleted the calendar.
    help! i am lost without my calendars....

    Hello ehfromiquique
    The article below will give some troubleshooting steps to resolve issues with calendars.
    iCloud: Troubleshooting iCloud Calendar
    http://support.apple.com/kb/TS3999
    Thanks for using Apple Support Communities.
    Regards,
    -Norm G.

  • Deleting Calendars

    I have the Blackberry Tour.  I am at the end of my rope.
    I was using Google Calendar and Syncing just fine.
    All of a sudden, I have 3 calendars on my phone -- Device Default, and one for each of my e-mail accounts.
    Data is all over the place.
    I want to delete all data (and calendars) and start fresh (i have my info backed up on my desktop.
    I am on a Mac if this helps.
    thanks!

    Using a PC, I've gone to Desktop Manager, then to Backup/Restore>Advanced and in there you can delete calendar info. One thing to remember is be sure to go to Options>Advanced Options>Defaut> and make sure the default Calendar and Messaging are set to the one you want to synch. 

  • How to recover/restore deleted calendar?

    How to recover/restore deleted calendar?

    Actually, restore deleted calendar got the same steps as restore deleted messages. You must be a Microsoft Exchange Server account.
    1.In the folder from which the item was deleted, or in the Deleted Items folder, on the Folder tab, in the Clean Up group, click Recover Deleted Items.
    Note: If the Recover Deleted Items command is missing
    An Exchange account is required for this command to appear. If you are using an Exchange account and don’t see the command, contact your Exchange administrator.
    2.Click an item, and then click Recover Selected Items .
    Note: Your Exchange administrator specifies the retention time for deleted items. After this time elapses, deleted items cannot be restored.
    More Reference:
    http://office.microsoft.com/en-us/outlook-help/recover-deleted-items-HA010355039.aspx
    Cheers,
    Tony Chen
    Forum Support
    Come back and mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback on our support, please contact
    [email protected]

  • Restore deleted calendar

    I accidentally deleted two calendars. I make daily iCloud backups. How can I restore my backed up calendars?
    Thanks!
    W

    Actually, restore deleted calendar got the same steps as restore deleted messages. You must be a Microsoft Exchange Server account.
    1.In the folder from which the item was deleted, or in the Deleted Items folder, on the Folder tab, in the Clean Up group, click Recover Deleted Items.
    Note: If the Recover Deleted Items command is missing
    An Exchange account is required for this command to appear. If you are using an Exchange account and don’t see the command, contact your Exchange administrator.
    2.Click an item, and then click Recover Selected Items .
    Note: Your Exchange administrator specifies the retention time for deleted items. After this time elapses, deleted items cannot be restored.
    More Reference:
    http://office.microsoft.com/en-us/outlook-help/recover-deleted-items-HA010355039.aspx
    Cheers,
    Tony Chen
    Forum Support
    Come back and mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback on our support, please contact
    [email protected]

Maybe you are looking for