Running an AppleScript at a specific time

Discussion in 'Mac Programming' started by rediffusion, Jan 6, 2014.

  1. rediffusion macrumors regular

    rediffusion

    Joined:
    Jun 26, 2006
    Location:
    Fairfield, CT
    #1
    Probably a silly question...

    I have created an AppleScript to run Dropbox....

    I want to make it run at 1am every night but can't work out how to do it. Do I use Automator?


    Thanks in advance,
    R ;)
     
  2. kryten2, Jan 6, 2014
    Last edited: Jan 6, 2014

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    Here's an launchd example that should run Dropbox every day at 1am. Save the below snippet into a plain text file in your ~/Library/LaunchAgents folder with the file name user.dropbox.nightly.plist

    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>user.dropbox.nightly</string>
              <key>ProgramArguments</key>
              <array>
                        <string>osascript</string>
                        <string>-e</string>
                        <string>activate application "Dropbox"</string>
              </array>
              <key>StartCalendarInterval</key>
              <dict>
                        <key>Hour</key>
                        <integer>1</integer>
                        <key>Minute</key>
                        <integer>0</integer>
              </dict>
    </dict>
    </plist>
    You can test it by using the following command in the Terminal application :

    Code:
    # this line loads the launchd job
    launchctl load Library/LaunchAgents/user.dropbox.nightly.plist
    
    # this line forces the job to trigger immediately rather than waiting until 1am
    launchctl start user.dropbox.nightly
    
    # this line unloads the plist, in case there's an error
    launchctl unload Library/LaunchAgents/user.dropbox.nightly.plist
     

    Attached Files:

  3. rediffusion thread starter macrumors regular

    rediffusion

    Joined:
    Jun 26, 2006
    Location:
    Fairfield, CT
    #3
    kryten2,

    Thank you SO much!!!! Just ran the Terminal test and it works great.

    R ;)
     
  4. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #4
    Great. Let's hope it also runs at the time it's supposed to. ;)
     
  5. rediffusion thread starter macrumors regular

    rediffusion

    Joined:
    Jun 26, 2006
    Location:
    Fairfield, CT
    #5
    i'll let you know ;)
     
  6. Johnny83 macrumors newbie

    Johnny83

    Joined:
    Dec 25, 2016
    #6
    Hi kryten2!

    On this topic I have a apple script which auto connects the vpn if it drops I would like to run it between 6pm and 8am. Can you help me with this please?
     

Share This Page