some issues with a reoccuring event

Discussion in 'Mac Programming' started by mufflon, Jul 19, 2007.

  1. macrumors 6502

    #1
    I must confess I'm not the most well versed when it comes to reoccuring events, especially those that i don't have to attend to every waking hour :)
    I have made a small imap php script to gather news to a site I'm developing on my spare time, but I don't know what to do :confused:

    Ideally the script should do:
    1) open any kind of browser
    2) go to site
    3) close browser

    every one hour

    the hardware I'm using is 10.4 server edition, though i'm not sure it matters

    I have sought high and low with rather crappy results, I might have looked in the wrong locations, but definetly not found anything.
     
  2. macrumors 601

    HiRez

    #2
    If it's something that just needs to run on your own machine, it sounds like a perfect job for AppleScript (although maybe I don't understand everything you're trying to do). You could also set up a cron event to fire it off every hour, or just have it run in the background continuously and activate once per hour.
     
  3. macrumors 6502

    #3
    Sigh and here I was trying to teach myself cron from random sites while applescript beckoned with simplicity. Tnx for the help though :)

    The script I made:

    Code:
    repeat with shotcount from 1 to 1000
    	tell application "Safari"
    		activate
    		set the URL of document 1 to "myURL"
    	end tell
    	delay (60 * 60 * 3)
    end repeat
    I reckon I can accept restarting the script once every 3000th hour or so =)
     
  4. macrumors 6502a

    #4
    why not curl or wget the page? or do you actually want to see the page?

    curl http://google.com > /dev/null
     
  5. macrumors 601

    HiRez

    #5
    Just make it an endless loop and put it in System Preferences > Accounts > Login Items and you won't ever have to touch it. I think there's a way to make AppleScripts run without showing up in the dock or command-tab view but I don't know how.
     
  6. macrumors 68040

    MongoTheGeek

    #6
    Try this. It will bog the system far less

    Code:
    on idle
    	tell application "Safari"
    		activate
    		set the URL of document 1 to "myURL"
    	end tell
    	return 3*hours
    end idle
    
    save it as a stay up application.

    if you really feel the need to use repeat and delay

    Code:
    repeat
    	tell application "Safari"
    		activate
    		set the URL of document 1 to "myURL"
    	end tell
    	delay (60 * 60 * 3)--this works but 3*hours is easier to read
    end repeat
     

Share This Page