PDA

View Full Version : Automated Apple Script?




stevento
Apr 5, 2008, 04:53 AM
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
Apr 5, 2008, 05:01 AM
You can use Lingon (http://lingon.sourceforge.net/) 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
Apr 5, 2008, 10:27 AM
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
Apr 5, 2008, 10:33 AM
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 (http://lingon.sourceforge.net/) 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
Apr 5, 2008, 11:25 AM
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).

stevento
Apr 5, 2008, 01:34 PM
I'm trying to play a prank on my roommate who doesn't know anything about computers

lee1210
Apr 5, 2008, 04:16 PM
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
Apr 5, 2008, 10:57 PM
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
Apr 5, 2008, 11:20 PM
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/linux-newbie/65695-using-crontab-start-script-every-5-min-pls-help.html

Cheers

stevento
Apr 6, 2008, 12:18 AM
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


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
Apr 7, 2008, 12:02 AM
here's a better question
how do i get terminal to run a script and continue running it after terminal closes?

CaptainZap
Apr 7, 2008, 07:51 AM
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...
osascript apple.scpt &

stevento
Apr 7, 2008, 06:47 PM
i love computers!
now let me ask you this, if i do that, how do i get it to stop?

CaptainZap
Apr 8, 2008, 07:26 AM
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....

$ play &
[1] 7154
$ kill 7154