Tuesday, June 18, 2019

#1 2003-09-22 09:13:52 pm

C. Mullins
Member
Registered: 2002-12-07
Posts: 19

Crontab and Applescript

Is there a way to edit my crontab so that it will execute an Applescript?  I guess what I am looking for is:
             1)Does the script have to compiled or saved as an application?

             2)Do I have to put another command as part of the crontab?

             3) #1 and #2 is assuming that it can be done.

Or is there another utility such as the old Do Script Scheduler for OS9 around now to use?

Thanks....

Offline

 

#2 2003-09-22 09:54:23 pm

Rob
Member
From:: Ohio, USA
Registered: 2002-11-20
Posts: 1886

Re: Crontab and Applescript

Or is there another utility such as the old Do Script Scheduler for OS9 around now to use?



Since I'm not familiar with cron, I'll offer these script scheduling utilities. If I'm not mistaken, Script Timer X is developed with AppleScript Studio by a fellow scripter. :-)

http://www.macupdate.com/search.php?key … utton.y=12

-- Rob

Offline

 

#3 2003-09-22 11:42:03 pm

Camelot
Member
From:: San Jose, CA
Registered: 2002-12-15
Posts: 629

Re: Crontab and Applescript

Is there a way to edit my crontab so that it will execute an Applescript?  I guess what I am looking for is:
             1)Does the script have to compiled or saved as an application?



If saved as an application, you can call it via cron just like you'd execute any other app (i.e. just reference it by pathname).
Alternatively, 'osascript' can compile and execute an applescript, either on the command line or sourced from a file.

The file can be a plain text copy of the script, or can be a compiled AppleScript - as long as the script was compiled in the data fork not the resource fork:

osascript -e 'beep' -- run the AppleScript code 'beep'
osascript /path/to/file.scpt -- run the compiled script /path/to/file.scpt
osascript /path/to/file.txt -- run the plain text script /path/to/file.txt

Offline

 

#4 2003-09-23 08:09:05 am

Brad Bumgarner
Member
From:: Denver, Colorado
Registered: 2002-11-20
Posts: 394
Website

Re: Crontab and Applescript

I use a program called "CronniX." It puts a GUI on cron. I save my scripts as applications and then have cron (via CronniX) run them at the appropriate time(s).

Hope this helps,
Brad Bumgarner, CTA

Offline

 

#5 2003-09-23 09:38:16 am

Camelot
Member
From:: San Jose, CA
Registered: 2002-12-15
Posts: 629

Re: Crontab and Applescript

I don't think the original poster's question was as much about how to setup cron as it was how to run an AppleScript via cron.

Offline

 

#6 2003-09-23 09:47:43 am

Brad Bumgarner
Member
From:: Denver, Colorado
Registered: 2002-11-20
Posts: 394
Website

Re: Crontab and Applescript

I don't think the original poster's question was as much about how to setup cron as it was how to run an AppleScript via cron.



Yeah. That's how I run applescripts via cron.

Offline

 

#7 2019-02-28 12:11:27 pm

earthsaver
Member
Registered: 2007-10-08
Posts: 10

Re: Crontab and Applescript

Thank you so much for the reference to osascript! Since installing Mojave last fall, I've been searching for a way to make my Folding@home client scripts automated again using cron. They got broken by Mojave.

Camelot wrote:

If saved as an application, you can call it via cron just like you'd execute any other app (i.e. just reference it by pathname).
Alternatively, 'osascript' can compile and execute an applescript, either on the command line or sourced from a file.

The file can be a plain text copy of the script, or can be a compiled AppleScript - as long as the script was compiled in the data fork not the resource fork:

osascript -e 'beep' -- run the AppleScript code 'beep'
osascript /path/to/file.scpt -- run the compiled script /path/to/file.scpt
osascript /path/to/file.txt -- run the plain text script /path/to/file.txt

Last edited by earthsaver (2019-02-28 12:12:04 pm)

Offline

 

#8 2019-03-04 09:26:55 am

CK
Member
From:: UK
Registered: 2018-11-04
Posts: 80

Re: Crontab and Applescript

earthsaver wrote:

Since installing Mojave last fall, I've been searching for a way to make my Folding@home client scripts automated again using cron. They got broken by Mojave.

This might provide a potential solution: Fixing cron jobs in Mojave

However, it's worth bearing in mind that cron has officially been deprecated in macOS for quite a few versions, and Apple have recommended using launchd instead.  Taken from this link:

As of MacOSX 10.4, cron became deprecated in favor of launchd. The biggest advantage of launchd is that it does not assume that your computer is always on (as cron does). Therefore, if your Mac is asleep when a scheduled job was supposed to run, it will automatically run when your Mac is awake.

And from the crontab manpage:

Darwin note: Although cron(8) and crontab(5) are officially supported under Darwin, their functionality has been absorbed into launchd(8), which provides a more flexible way of automatically executing commands.  See launchctl(1) for more information.



If you're interesting in using launchd to schedule your AppleScripts, then here's a short guide. You can adapt the example from that link to execute an AppleScript by replacing the ProgramArguments key in theirs with this:

<key>ProgramArguments</key>
<array>
                <string>/usr/bin/osascript</string>
                <string>/full/path/to/your.applescript</string>
</array>

(or .scpt).  Avoid spaces in the file path.  To supply code by way of a command line argument, I think you can do this:

<key>ProgramArguments</key>
<array>
                <string>/usr/bin/osascript</string>
                <string>-e</string>
                <string>"beep"</string>
</array>

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)