Using Automator and iCal together in Lion

Discussion in 'Mac Apps and Mac App Store' started by Grimsrud, Aug 16, 2011.

  1. Grimsrud macrumors member

    Joined:
    Aug 11, 2010
    #1
    I'm trying to set up a process that will open a webpage at a certain time of the day, but when I save it in Automator, it does not open up iCal and create a calendar event as a couple guides (including the official one from Apple) I've read said it should. Is this an compatibility issue between Automator and the newest version of iCal that comes with Lion, or am I just missing something obvious?
     
  2. res1233 macrumors 65816

    res1233

    Joined:
    Dec 8, 2008
    Location:
    Brooklyn, NY
    #2
    I wouldn't use Automator. I'd use a launch daemon and an AppleScript, but those take some learning. Could you attach the action you made so I could take a look? Zip it first.
     
  3. archiewinter macrumors newbie

    Joined:
    Jan 5, 2009
    #3
    The solution

    It's not as difficult as it seems, although I had to work it out (again). I tried to use an automator application that I used frequently once upon a time, to launch an app every evening at a specific time, within iCal but that no longer worked.

    All you need to do is create a new iCal Alarm from the "document type" dialog when you first open Automator.

    Create your workflow, click save and it automagically adds it to a calendar event, so you can set time and date etc.

    No need to do anything else.

    AW
     
  4. Dorv macrumors regular

    Joined:
    Feb 11, 2008
    #4
    "automagically" not so much for me.

    The procedure runs just fine for me if I run it manually, but once scheduled, nothing happens (Other than the App showing up in Activity Monitor).
     
  5. tcampb01 macrumors newbie

    Joined:
    Mar 31, 2005
    #5
    The key elements are:

    1) After you create the workflow, you do a "Save as..." this is where you get to name it, but there's a pulldown selection to decide if you want to save it as a "Workflow" or as an "Application". You MUST save it as type "Application". If you save it as a "Workflow" then it'll just open in the Automator GUI but it won't run. If you save it as an "Application" then it'll actually run whenever it is opened.

    2) On my macs, if I select the template to create an iCal action, it doesn't automatically open iCal and let me fill in the details for when I want it launched. Not sure why... but I've tried it on several Macs and they're all the same (even though I'm following Apple's own documentation for Automator which says it's supposed to do that.) HOWEVER... I find that I can get around this by just creating my own iCal appointment, and in the "alert" field, set the alert to "open file". There's a sub-type that will default to "iCal". Click on the word "iCal" and in the flyout menu, select "other". This will pop open a finder window which will allow you to navigate to and select the Automator "application" you created in the above step.

    After doing both of these things (making sure it's saved as type "Application" and manually creating the iCal entry via the "Open File" alert option) it does work.

    On the advice of another webpage, I added a new calendar to iCal (rather than using one of the default "Home" or "Work" calendars) called "Automator" and used that to schedule the daily recurring event. I then un-check the calendar from the list of calendars to display (this doesn't delete it ... it's still there and it still runs everything, it just hides it so that you don't see the appointment for the various actions you want automator to perform on schedule.)
     
  6. RossW macrumors newbie

    Joined:
    Aug 24, 2012
    #6
    I followed tcampb01's instructions and it 'seemed' to work, but then I just realized it hasn't run since the date I originally created the recurring event in iCal (using the method described to create a new calendar, Automator, and hiding it from view). The recurring event in iCal looks right; if I manually run the Automator application it all works, but it's not being kicked off every night at 5 am.

    Any ideas?
     
  7. RossW macrumors newbie

    Joined:
    Aug 24, 2012
  8. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #8
    @RossW

    Can you attach your Automator app to your post or describe what the app does? You could easily create a launch agent for this kind of recurring event.
    There's even an app that can do all the work for you called Lingon.

    Info : http://www.peterborgapps.com/lingon/
     
  9. RossW macrumors newbie

    Joined:
    Aug 24, 2012
    #9
    I don't think it's the Automator actions that are the problem - I now see a popup alert from iCal saying that the 'Open file' alert doesn't run because the .app file couldn't be opened (See attached file).
     

    Attached Files:

  10. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #10
    When using a launch agent there's no need for iCal. You said the Automator app runs fine manually but in combination with iCal it clearly doesn't. Check your logs in the Console application for more information why the app couldn't be opened.
     
  11. RossW macrumors newbie

    Joined:
    Aug 24, 2012
    #11
    I tried Lingon but no luck there either (pointing to my Automator app). Are there logs for that?
     
  12. kryten2, Oct 13, 2012
    Last edited: Oct 13, 2012

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #12
    Have you checked the Console application? Can you attach your Automator app to your post or describe what the app does? Post a screenshot of the XML configuration file that Lingon made. It should be in your ~/Library/Launch Agents directory. Based on the iCal message it has something to do with backing up your Comic collection. I'm assuming copying files of some filetype from one location to another. If that's the case it should be scriptable with Applescript. Or is there some other kind of voodoo inside the app?


    Example :

    You could save a property list like this as ~/Library/LaunchAgents/some.label.plist.

    Code:
    <?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>some.label</string>
        <key>ProgramArguments</key>
        <array>
            <string>automator</string>
            <string>/path/to/example.workflow</string>
         </array>
        <key>RunAtLoad</key>
        <true/>
    </dict>
    </plist>
    It has to be loaded first by running in Terminal :

    Code:
    launchctl load ~/Library/LaunchAgents/some.label.plist
    or logging out and back in once.

    Check the Console application and filter for launch.
     

    Attached Files:

  13. RossW macrumors newbie

    Joined:
    Aug 24, 2012
    #13
    No Voodoo. Sole file copy from one folder to another scheduled for once a day (thru iCal it Lingon - neither works). I'd be happy with doing AppleScript but (a) don't have any experience with it, and (b) I thought an iCal alarm won't run an AppleScript file with a recent OS update)
     
  14. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #14
    a) I could do that for you if you provide me with the information I need.
    b) You're right about that. Fortunately a launch agent doesn't have that restriction.(at least to my knowledge I could be wrong)
    c) Only trying to help. It's a free world the choice is yours.
     
  15. RossW macrumors newbie

    Joined:
    Aug 24, 2012
    #15
    Thanks kryten2 - believe me when I say i really appreciate the help. I've attached some screenshots which I hope explain what I'm trying to do. Basically, I'm just copying a file from a folder in Dropbox to a local folder on my Mac using an Automator .app file. I've included the Lingon config screen and my Terminal output.
     

    Attached Files:

  16. kryten2, Oct 13, 2012
    Last edited: Oct 13, 2012

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #16
    Sorry, I was a little busy answering another post in another thread. Did you notice the line 12:47:53 PM (Backup Comic Collection) Unknown key : LingonWhat. Could you attach the configuration file that Lingon made? It should be in the LaunchAgents folder that's in your user's Library folder and should have Backup Comic Collection in its name. I attached an example screenshot of mine. Give me a couple of minutes to absorb the information in your post.

    Edit : Can't really make out the paths to the folder in Dropbox and the local folder. Post a screenshot after you run the workflow but when you do first click the results thingy in both actions so the actions shows the resulting paths or screenshots from Finder like mine which show the path bar.
     

    Attached Files:

  17. RossW macrumors newbie

    Joined:
    Aug 24, 2012
    #17
    Here's my plist file. The actual name of the Automator .app file is "Automator_App_Comic_Collection_Backup.app"
     

    Attached Files:

  18. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #18
    Thanks for the plist file. Did you see my edit?
     
  19. RossW macrumors newbie

    Joined:
    Aug 24, 2012
    #19
    Here's a screenshot of the workflow while running (Automator crashed for the first time on me so it didn't finish).

    Dropbox location of source file: Comics\RossW.cmp
    Documents location of target: Documents\Comics\Comic Collector\Backup from Dropbox

    Is it the spaces in the target folder path?
     

    Attached Files:

  20. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #20
    Copy this script in ScriptEditor and run it to see if it copies the file from the right source to the right destination.

    Code:
    set theSourceFolder to (path to home folder as text) & "Dropbox:Comics:" as alias
    set theDestinationFolder to (path to documents folder as text) & "Comics:Comic Collector:Backup from Dropbox:" as alias
    tell application "Finder"
    	set theContents to entire contents of theSourceFolder
    	duplicate theContents to theDestinationFolder with replacing
    end tell
    
     
  21. RossW macrumors newbie

    Joined:
    Aug 24, 2012
    #21
    It works! Of course, I have no idea how to schedule this to run every day with Lingon. Do I need to just point Lingon to a saved AppleScript file, or does it need more parameters in the What field?
     
  22. RossW macrumors newbie

    Joined:
    Aug 24, 2012
    #22
    Spoke (slightly) too soon - AppleScript popped up an error saying the AppleEvent timed out (the file is big - about 1.8 GB) although the copy seemed to continue and eventually completed just fine.
     

    Attached Files:

  23. kryten2, Oct 13, 2012
    Last edited: Oct 13, 2012

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #23
    Ok, now we're getting somewhere. The time out should be solved with an added statement in the script. Don't know it by heart, will have to look it up. Shouldn't take too long. I would make a plist manually if you can and leave Lingon out of it.

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    	<key>Label</key>
    	<string>some.label</string>
    	<key>Program</key>
    	<string>/usr/bin/osascript</string>
    	<key>ProgramArguments</key>
    	<array>
    		<string>osascript</string>
    		<string>/Users/yourusername/Library/Scripts/nameofyourscript.scpt</string>
    	</array>
    	<key>RunAtLoad</key>
    	<true/>
    	<key>StartCalendarInterval</key>
    	<dict>
    		<key>Hour</key>
    		<integer>12</integer>
    		<key>Minute</key>
    		<integer>36</integer>
    	</dict>
    </dict>
    </plist>

    Change some.label and the path to your script line and the values in the StartCalendarInterval to see if it kicks in at the specified time.
    I post a modified script in a few minutes.
    Remember to load it with :

    Code:
    launchctl load ~/Library/LaunchAgents/nameofyour.plist
    Edit : If an event takes longer than two minutes, the Apple Event Manager reports a time-out error. If 5 minutes isn't enough increase the timeout.

    Code:
    set theSourceFolder to (path to home folder as text) & "Dropbox:Comics:" as alias
    set theDestinationFolder to (path to documents folder as text) & "Comics:Comic Collector:Backup from Dropbox:" as alias
    tell application "Finder"
    	set theContents to entire contents of theSourceFolder
    	with timeout of 300 seconds
    		duplicate theContents to theDestinationFolder with replacing
    	end timeout
    end tell
    
     
  24. RossW macrumors newbie

    Joined:
    Aug 24, 2012
    #24
    Had to bump up the timeout, but I think everything is working now (my plist file attached).

    Thanks so much kryten2!
     

    Attached Files:

  25. otomo, Dec 8, 2014
    Last edited: Dec 8, 2014

    otomo macrumors member

    Joined:
    Jul 13, 2013
    #25
    How do you get at this iCal Alarm later if you want to edit/modify it?

    Update: Ah, found it in my Open Recent menu and then traced it back to ~/Library/Workflows/Applications/iCal/ folder.
     

Share This Page