some issues with a reoccuring event

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

  1. mufflon
    Expand Collapse
    macrumors 6502

    Joined:
    Sep 15, 2006
    #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. HiRez
    Expand Collapse
    macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #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. mufflon
    Expand Collapse
    thread starter macrumors 6502

    Joined:
    Sep 15, 2006
    #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. semaja2
    Expand Collapse
    macrumors 6502a

    Joined:
    Dec 12, 2005
    Location:
    Adelaide
    #4
    why not curl or wget the page? or do you actually want to see the page?

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

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #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. MongoTheGeek
    Expand Collapse
    macrumors 68040

    MongoTheGeek

    Joined:
    Sep 13, 2003
    Location:
    Its not so much where you are as when you are.
    #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