AppleScript iCal

Dear Lazyweb, is there a way to nuke the "Organizer" field from an iCal event from AppleScript?

If I export an event from Facebook as an .ics file that is then imported into iCal, it has an "Organizer", which iCal interprets as, "I should not let you edit the summary text of this event in your own calendar."

I have on occasion been able to make these events editable by copying them and then deleting the original, but I'm not entirely sure how: most of the time I get stuck in a dialog asking me to "send invitations" that won't go away and I have to force-quit iCal.


Update: I don't see a way to fix the events that are already imported into iCal, but here's a way to fix new events at the time at which they are imported: ics-handler.scpt.

Tags: , , ,

9 Responses:

  1. Maybe a script that claims the ics export and deletes the line from the ics file before it even gets to iCal?
    Also- iCal is an abomination. Try the 30 day trial of BusyCal.

    • jwz says:

      I have no idea how to do that.

      I don't have much of a beef with iCal, but I am definitely not interested in even exploring something that won't integrate properly with the iOS ecosystem (as enumerated in this previous shitshow).

      • I am in complete agreement with the opinions expressed in the aforementioned shitshow. BusyCal is pretty much a drop-in replacement for iCal, except, tons less bugs. But this is irrelevant to your original question.

        Back to that: Build something that opens ics files[1]. Set it to be the default app for ics files[2]. Now when you click the export link in Facebook, your thing opens the ics file[3]. It does a grep -v 'Organizer: ' on the file, and then has iCal open the new edited file.[4]

        [1] An AppleScript saved as an App should work.
        [2] Probably set via 'Get Info' in the Finder on an ics file.
        [3] I'm assuming that Safari uses the system document bindings that you just configured in [2].
        [4] For "it", I'd do a quick search on using AppleScript to run a shell script, since AppleScript is a fast way to make an App-like-thing, and the actual work here is like 2 lines of bash. Depending on your mood, you could also just make an actual App. The key here is [2] and [3] to run your MITM.

        • John Bloom says:

          I was working on mine during the time you posted. :) I had issues with just stripping out the Organizer; line from facebook event ics files. Is there some other trick besides the grep -v? Or maybe iCal is more flexible about parsing ics files in newer versions of OS X? (Using 10.5 here)

        • jwz says:

          Thanks, I think I made it work: ics-handler.scpt.

        • tfb says:

          BusyCal is fine apart from not supporting AppleScript, which is a significant limitation in this context, apparantly imposed by Apple.

  2. John Bloom says:

    I didn't even realize I could get facebook to actually give me an ICS. That's awesome. In thanks, here's a horrible hackjob of an Automater workflow I made:
    1. Get Selected Finder Items
    2. Run Shell Script:
    sed -e 's/^ORGANIZER;CN=.*:MAILTO:noreply@facebookmail.com/ORGANIZER;CN="Your Name":MAILTO:you@example.com/' -i .bak "$1";
    echo "$1";

    3. Open Finder Items: Open with iCal.app

    Known pitfalls: The quotes around "Your Name" are required. "Your Name" and email must match your 'Me' vCard in iCal exactly or this won't work (AFAICT).
    Possible pitfalls: I have no clue if iCal will insist on sending notification emails to everyone if you try to delete this event. In that case more thorough munging may be necessary.

    Save that as an App. Make it the default handler for .ics files. Improvements and bug reports welcome. Tested with 10.5.8/PPC.

  3. Arvid says:

    Awesome! Thanks. This is fantastic!

    I couldn't get the applescript app I saved to be the default app to open .ics files in OSX 10.6.8 - it just always reverted to iCal immediately when I clicked "change all…". So i did one better, which is to write a folder action script that I attach to my Downloads folder that detects any new .ics files and applies your script. Also made iCal activate automatically for choosing which calendar the .ics will go into:

    on adding folder items to this_folder after receiving added_items

    repeat with F in added_items
    set ext to the name extension of (info for F)
    if ext is "ics" then
    set F to POSIX path of F
    set F2 to F & ".tmp"
    set FQ to quoted form of F
    set FQ2 to quoted form of F2

    -- Delete these fields from the file

    set CMD to "grep -v '^\\(ORGANIZER\\|ATTENDEE\\|PARTSTAT\\)[;:].*'"
    set CMD to CMD & " " & FQ

    -- Overwrite the original file
    set CMD to CMD & " > " & FQ2
    set CMD to CMD & " ; mv " & FQ2 & " " & FQ
    do shell script CMD

    -- Open the file with Calendar, then delete it.
    tell application "iCal"
    activate
    open {F}
    end tell

    do shell script "rm " & FQ
    end if
    end repeat
    end adding folder items to