Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

stevento

macrumors 6502
Original poster
Dec 10, 2006
252
0
Los Angeles
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?
 

xUKHCx

Administrator emeritus
Jan 15, 2006
12,583
9
The Kop
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?
 

tacoman667

macrumors regular
Mar 27, 2008
143
0
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!
 

xUKHCx

Administrator emeritus
Jan 15, 2006
12,583
9
The Kop
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.


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.


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?

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

johnellisdm

macrumors member
Feb 21, 2007
50
0
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).
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
I'm trying to play a prank on my roommate who doesn't know anything about computers

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
 

stevento

macrumors 6502
Original poster
Dec 10, 2006
252
0
Los Angeles
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
 

GroovyLinuxGuy

macrumors regular
Apr 2, 2006
139
0
Canada
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

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
 

stevento

macrumors 6502
Original poster
Dec 10, 2006
252
0
Los Angeles
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
 

stevento

macrumors 6502
Original poster
Dec 10, 2006
252
0
Los Angeles
here's a better question
how do i get terminal to run a script and continue running it after terminal closes?
 

CaptainZap

macrumors regular
Jan 17, 2007
170
0
here's a better question
how do i get terminal to run a script and continue running it after terminal closes?

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 &
 

CaptainZap

macrumors regular
Jan 17, 2007
170
0
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.