1 2 Previous Next 18 Replies Latest reply: Jun 9, 2013 6:44 PM by Topher Kessler
James Rydings Level 2 Level 2 (175 points)

I created a script that checks for an internet connection, and if present backsup some important files if modified to my server using Transmit. I would like it to run in the background once a day. I currently have it set up to run daily in iCal which works fine, but I now have all these iCal events listed on all my iDevices. Is there another way I can do this?


iMac, Mac OS X (10.7.3), 3.06 ghz, 4gb, 512mb
  • 1. Re: Run script daily in background
    Jeffrey Jones2 Level 6 Level 6 (8,510 points)

    What's wrong with Calendar (formerly iCal)? If you just don't want to see the events, put them in a special calendar then uncheck it so that the events aren't displayed.

  • 2. Re: Run script daily in background
    Linc Davis Level 10 Level 10 (117,765 points)

    Move the event to a calendar that isn't synced with the other devices.

  • 3. Re: Run script daily in background
    James Rydings Level 2 Level 2 (175 points)

    I already have it not showing my computer, but I dont know how to hide it from my iOS devices.

    How do I create a calander on my mac only which does not sync to iCloud?

  • 4. Re: Run script daily in background
    Linc Davis Level 10 Level 10 (117,765 points)

    File > New Calendar > On My Mac

  • 5. Re: Run script daily in background
    Barney-15E Level 8 Level 8 (35,275 points)

    If you don't have the ability to add a calendar to On My Mac, enable the Birthdays calendar in preferences, then select it in the list of calendars. Below that, right-click in the empty space and select New Calendar. It will be created in the "ON MY MAC" section.

  • 6. Re: Run script daily in background
    Topher Kessler Level 6 Level 6 (9,340 points)

    What type of script is it?

     

    To run a script once per day in the background, you can create a launch agent for your account or for the system that will run the script in the background. To do this, create a plain text file with the following contents, and save it with the file extension ".plist" in the LaunchAgents directory (for instance "dailytask.plist").

     

    You can do this by holding the Option key and choosing Library from the Finder's Go menu, and then navigating to the LaunchAgents folder. Keep this folder open so it will be accessible.

     

    Next, open TextEdit and create a new document, then press Shift-Command-T to make it a plain text document, and then copy the following contents to the document and save it to your desktop.

     

    <?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>local.dailytask</string>
              <key>ProgramArguments</key>
              <array>
                        <string>/PATH/TO/SCRIPT/GOES/HERE</string>
              </array>
              <key>QueueDirectories</key>
              <array/>
              <key>StartCalendarInterval</key>
              <dict>
                   <key>Hour</key>
                   <integer>12</integer>
                   <key>Minute</key>
                   <integer>30</integer>
              </dict>
    </dict>
    </plist>
    

     

    Now change the text that read "PATH/TO/SCRIPT/GOES/HERE" to be the full path to the location of your script, so for instance if your script is called "myscript.sh" and is in your Documents folder, then you would put the following (replacing "username" with the short name of your account--ie, your home folder name):

     

    /Users/username/Documents/myscript.sh

     

    Next locate where it says Hour and Minute, and change these to be the desired time you want the script to run (hours are in 24-hour format).

     

    With these changes made, save the document and then rename it so instead of having ".txt" as the extension, make the extension be ".plist" (confirm the change when prompted). Then copy or move the file from your Desktop to the open "LaunchAgents" folder.

     

    With this setup, now log out and log back into your account, and the system should run the designated script at the appropriate time.

     

    Do keep in mind to use AppleScripts you will need to specify more details instead of just the path to script as I mentioned above, or optionally you can have the path here point to a small secondary shell script that itself will contain a command to run the desired AppleScript or other script.

     

    Lastly, the use of the LaunchAgent folder in your home directory means this script will only load when you log in, and will run under the scope of your user account. If you want it to run for all users or even if the system is at the login window, then you will have to use the global LaunchAgents directory in the Macintosh HD > Library folder.

     

    If you run into any hurdles with this approach, post back here and folks will be glad to help you set it up.

  • 7. Re: Run script daily in background
    James Rydings Level 2 Level 2 (175 points)

    Topher that sounds more like what im after.

    Below is the plist file I created (so the script should run every 30 mins). Does it seem correct? Also is there a way I can create a log file recording evertime it runs so I can make sure it working correctly?

     

    <?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>com.jamesrydings.AutoBackup</string>

              <key>ProgramArguments</key>

              <array>

                        <string>/Users/jamesrydings/Documents/FTP Backup Scripts/Backup two.app</string>

              </array>

              <key>QueueDirectories</key>

              <array/>

              <key>RunAtLoad</key>

                         <true/>

                         <key>StartInterval</key>

                         <integer>1800</integer>

              </dict>

    </dict>

    </plist>

  • 8. Re: Run script daily in background
    putnik Level 3 Level 3 (690 points)

    I should think that Time Machine would perform regular backups like this?  You can exclude items not required and keep a regular backup schedule.

  • 9. Re: Run script daily in background
    James Rydings Level 2 Level 2 (175 points)

    Timemachine makes onsite bacups of my whole machine. This is to make offsite backups of some selected files to my server.

  • 10. Re: Run script daily in background
    Linc Davis Level 10 Level 10 (117,765 points)

    That won't work.

  • 11. Re: Run script daily in background
    drdocument Level 4 Level 4 (2,995 points)

    As a possible alternative...

    Have you considered creating a pair of sync'ed folders between your Mac and your server?

    It might be less hassle than a script.

  • 12. Re: Run script daily in background
    James Rydings Level 2 Level 2 (175 points)

    Topher, my plist file will not load.

    After doing some research I have updated my plist file to follows:

     

    <?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>com.jamesrydings.AutoBackup</string>

        <key>ProgramArguments</key>

        <array>

            <string>/Users/jamesrydings/Documents/FTP Backup Scripts/Backup two.app</string>

        </array>

        <key>StartInterval</key>

        <integer>86400</integer>

    </dict>

    </plist>

     

     

    However it still doesnt work. I tried the following launch command:

    launchctl load /Users/jamesrydings/Library/LaunchAgents/com.jamesrydings.AutoBackup.plist

    launchctl: no plist was returned for: /Users/jamesrydings/Library/LaunchAgents/com.jamesrydings.AutoBackup.plist

    launchctl: no plist was returned for: /Users/jamesrydings/Library/LaunchAgents/com.jamesrydings.AutoBackup.plist

    nothing found to load

     

    I also tried the following command:

    sudo launchctl load -w -F /Users/jamesrydings/Library/LaunchAgents/com.jamesrydings.AutoBackup.plist

    launchctl: no plist was returned for: /Users/jamesrydings/Library/LaunchAgents/com.jamesrydings.AutoBackup.plist

    launchctl: no plist was returned for: /Users/jamesrydings/Library/LaunchAgents/com.jamesrydings.AutoBackup.plist

    nothing found to load

     

    I then tried this:

    plutil -lint /Users/jamesrydings/Library/LaunchAgents/com.jamesrydings.AutoBackup.plist

    /Users/jamesrydings/Library/LaunchAgents/com.jamesrydings.AutoBackup.plist: Unexpected character { at line 1

     

    There is no { character on line 1. Any thoughts?

  • 13. Re: Run script daily in background
    putnik Level 3 Level 3 (690 points)

    You can use Time Machine on a network too.  As I said, you can exclude folders you don't want to backup, though once the initial run has completed the backups will be only of changed files.  It has the advantage that you can recover the system from it.

  • 14. Re: Run script daily in background
    Topher Kessler Level 6 Level 6 (9,340 points)

    James,

     

    It appears you are trying to launch an application directly with the launch agent. This can be done using the "open" command in the launch agent in the following manner (changes are in bold):

     

    <?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>com.jamesrydings.AutoBackup</string>
              <key>ProgramArguments</key>
              <array>
                        <string>open</string>
                        <string>/Users/jamesrydings/Documents/FTP Backup Scripts/Backup two.app</string>
              </array>
              <key>QueueDirectories</key>
              <array/>
              <key>RunAtLoad</key>
              <true/>
              <key>StartInterval</key>
              <integer>1800</integer>
    </dict>
    </plist>
    

     

    My guess is you created an AppleScript or Automator application, in which case this will run it as you wish on the designated time interval (or calendar time). If the system is asleep or off during this time, then it will queue up the missed instance and run it the next time the system is awake, and then continue at the set interval time.

1 2 Previous Next