Automated Apple Script?

Discussion in 'Mac Programming' started by stevento, Apr 5, 2008.

  1. macrumors 6502

    stevento

    Joined:
    Dec 10, 2006
    Location:
    Los Angeles
    #1
    Is there a way to write an apple script to run itself without any provocation at all?
    for instance to tell it to run at a certain time or to run whenever a certain event happens?
     
  2. Administrator emeritus

    xUKHCx

    Joined:
    Jan 15, 2006
    Location:
    The Kop
    #2
    You can use Lingon to launch the script (might have to save it as an application from script editor) at certain times/intervals/lots of other things.

    Or you could look at using the script as a "folder action" that is when something happens to a folder the script will be launched.

    What is it you are trying to do?
     
  3. macrumors regular

    Joined:
    Mar 27, 2008
    #3
    I would love to know the answer to this as well. I have a script i saved as a application which registers a kext file in order to use a fan control application. The system doesn't seem to save the terminal induced kextload command and so everytime I reboot or shutdown, it unloads without reloading at boot. I would like to make my script run at login or when the desktop shows like in a Windows system with startup. Plus, is there a way to make the commands use my admin password and not ask me to login everytime I want to run the code?

    I do not mean to hijack the thread but this actually pertains to the same situation as the OP so answers are probably going to benefit both of us.

    Thanks!
     
  4. Administrator emeritus

    xUKHCx

    Joined:
    Jan 15, 2006
    Location:
    The Kop
    #4


    Can either hardcode it into the script or use keychain scripting to get the password out from there
     
  5. macrumors member

    Joined:
    Feb 21, 2007
    #5
    i use ical to kick off my scripts (backups, rsyncing my iphoto library to all the computers in the house, etc).

    it is very easy to use, you just create an ical event, then under "alarm" choose run script. i cal doesn't need to be running to trigger the event. also, you can use the rich scheduling (repeat features, etc).
     
  6. thread starter macrumors 6502

    stevento

    Joined:
    Dec 10, 2006
    Location:
    Los Angeles
    #6
    I'm trying to play a prank on my roommate who doesn't know anything about computers
     
  7. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #7
    you're less likely to be caught if you use cron or at from the terminal for scheduling. Run 'man at' or 'man cron' to get info.

    Make sure it happens at a different time each day. Consistency would raise ire. If you use at the script will have to reschedule itself, but randomizing the time would be easier. For cron you will need multiple lines to change when it runs. Something that repeats each week is probably random enough. If you can put a random length sleep in the script that will help too. Humans normally don't act right on the minute, so the script shouldn't either.

    I feel a bit guilty. Don't delete any of your friend's stuff with this.

    -lee
     
  8. thread starter macrumors 6502

    stevento

    Joined:
    Dec 10, 2006
    Location:
    Los Angeles
    #8
    what's the command run a script in terminal?
    or better yet what's the script syntax to run another script?
    what i want to do is have it run every 5 minutes
     
  9. macrumors regular

    GroovyLinuxGuy

    Joined:
    Apr 2, 2006
    Location:
    Canada
    #9
    open a terminal and type

    man cron

    This will give you the manual page for cron which will run your script at what ever time you want.

    If the man page is too much for you, and it may be, I know I have troubles with them sometimes you can always google something similar to
    cron + 5 min

    Here is the first search result to get you started

    http://www.linuxforums.org/forum/li...rontab-start-script-every-5-min-pls-help.html

    Cheers
     
  10. thread starter macrumors 6502

    stevento

    Joined:
    Dec 10, 2006
    Location:
    Los Angeles
    #10
    can i use the on keyword to attach a script to the desktop?

    for instance i'll attach a folder action to the desktop then in that script it'll say
    Code:
    
    on run
    -- code to be done
    end run
    
    
    is that somewhere along the lines?
    what i want to try to do is whenever he clicks into the desktop it runs
     
  11. thread starter macrumors 6502

    stevento

    Joined:
    Dec 10, 2006
    Location:
    Los Angeles
    #11
    here's a better question
    how do i get terminal to run a script and continue running it after terminal closes?
     
  12. macrumors regular

    Joined:
    Jan 17, 2007
    #12
    Well to run a script in Terminal you can use osascript and then you can always add a & onto the end of it so it is always running. So like...
    Code:
    osascript apple.scpt &
     
  13. thread starter macrumors 6502

    stevento

    Joined:
    Dec 10, 2006
    Location:
    Los Angeles
    #13
    i love computers!
    now let me ask you this, if i do that, how do i get it to stop?
     
  14. macrumors regular

    Joined:
    Jan 17, 2007
    #14
    Well when you use that command it spits out a PID for you. And you can use that PID to kill it whenever you want, but I wouldn't know how to automate it. Here is an example....

    Code:
    $ play &
    [1] 7154
    $ kill 7154
    
     

Share This Page