AppleScript help needed

Discussion in 'Mac Programming' started by akadmon, Dec 24, 2007.

  1. akadmon macrumors 68010

    Joined:
    Aug 30, 2006
    Location:
    New England
    #1
    Can anyone point me to an script that closes an application at a certain time and saves the active file? I'm in the process of digitizing my hi 8 video library and I often find myself wishing I could tell iMovie to quit 2 hours after starting the conversion (i.e. at the end of the tape) so that I don't have to be babysitting the whole process. Without this iMovie will continue filling up the hard drive space even after the tape ends, unless I manually stop the import. I'm sure this is a very simple thing to do in AppleScript, but I have no clue how to do this, since I've never used AS. I would appreciate some help here.
     
  2. numero macrumors regular

    Joined:
    Jul 23, 2002
    Location:
    OR
    #2
    Give this a try. Start your tape and then launch this script.

    iMovie HD isn't scriptable, but you can get some stuff done by calling it to the front and issuing key commands. Since your project already has a name and location, all you have to do it get it to save. You may need more than a 5 second delay between the save and the quit. I didn't actually try this with a capture session active. You may also want to capture for slightly more than 2 hours.

    Let me know how this works out.

    -numero




    Code:
    -- 60 seconds * 60 minutes * 2 hours
    delay 60 * 60 * 2
    
    tell application "iMovie HD"
    	activate
    end tell
    
    tell application "System Events"
    	keystroke "s" using command down
    	delay 5
    	keystroke "q" using command down
    end tell
     
  3. akadmon thread starter macrumors 68010

    Joined:
    Aug 30, 2006
    Location:
    New England
    #3

    OK, thanks. I'll try this when I get home.
     
  4. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #4
    What is it with Apple having such poor AppleScript support in their own applications? It doesn't set a very good example. Aren't they embarrassed by the richness of AppleScript dictionaries of, for example, Adobe apps? Even many inexpensive shareware apps put Apple's own apps to shame in terms of AppleScript support. Especially the pro apps, where people really need to use batch processing and automation.
     
  5. akadmon thread starter macrumors 68010

    Joined:
    Aug 30, 2006
    Location:
    New England
    #5
    I tried it and it works, but I had to modify it a little, since issuing the :apple:+s commad brings up a Do you want to save changes to... dialog, which requires a yes answer in order to allow iMovie to quit. Here is the modified script

    Code:
    
    -- 60 seconds * 60 minutes * 2 hours
    delay 60 * 60 * 2
    
    tell application "iMovie HD"
    	activate
    end tell
    
    tell application "System Events"
    	keystroke "s" using command down
    	delay 5
    	keystroke "q" using command down
    	delay 5
    	keystroke "enter"
    end tell
    
    Thanks a bunch! :)
     

Share This Page