do shell script (file)

Hi folks.

How can I get the Calendar app to run a script I’ve written? It’s multiple lines, and I want to keep it written like this, but have it called/run by the “cron” in Calendar.

Cheers

Hello! nothing easier than that!

You use the run script that runs AppleScript from calendar that script should look something like this:

Remember to check if any environment variables your script may rely on, exists in the do shell script. :slight_smile:

do shell script "/path/to/your/shell/script"

Hi there. Thanks for the reply.

That part I have. I need to call the AS in order to get this done, but the Calendar app just opens the AS window instead of running it.

Cheers

I don’t have the calendar app, as I am still on Snow Leopard, but how about running the script as an applet from Calendar.app?

Hi there.

Tried saving it as an “app” but Calendar won’t launch it. Not choosable in dialog box. So not sure how to get AS to launch a native Bash script.

Cheers

Ok.

You have a script (or had), that consisted of a line with a do shell script in it.

Now we’ll call that script from Calendar.app like this:


tell application "AppleScript Runner"
	run script file "hfs:path:to:the:do:shell:script"
end tell

I have high hopes in that this will work. :slight_smile:

Hi everybody,

Calendar application can’t run anything less than a full application. Unix executables aren’t applications right? Anyway what you can do is create an AppleScript app or a Automator workflow which runs a script.

I’ll try to run a unix script with Calendar.

gl,
kel

Hi,

Unix exacutables don’t run from Calendars open file. They open in Xcode.

gl,
kel

Hi daBee,

Your script is not working because you’re trying to run a unix script in Script Editor. You can save your unix script as text and run it from a Applescript application with ‘do shell script’ as McUsr said. Another way is to embed the unix script in an AppleScript application. Quoting might be hard at the beginning.

I couldn’t think of a good example yet.

gl,
kel

Hi there. I think it’s time for some clarity.

  • Basically I want to use Calendar as a cron to run a script that does a mysqldump on a daily basis. I would LIKE to use Calendar because it’s handy, and I want to see how I can use Calendar in the future for items like this. It’s handy. Yes I can use the Crontab, but I’d like to focus on the Calendar to launch this file before I have to go to the Crontab method.

  • I currently have an AppleScript that has the following:

do shell script “/Library/WebServer/Documents/domain/subdirectory/scripts/myScript1.sh” user name “root” password “alpha” with administrator privileges

  • I have tried saving it with a scptd file suffic, applescript file suffix, app file suffix, and scpt file suffix. Calendar will only allow the scpt and scptd file suffices. Neither work. It just opens the file in AE. So for that matter, Calendar cannot initiate an AppleScript, as I see it.

Cheers

Certainly is. :wink:

  1. Save the AppleScript as an application (select “Application” in the “File Format” pop-up menu in the “Save As.” dialog in AppleScript Editor) with the default “.app” extension.
  2. Set an “Open File” alarm in your Calendar event with the script application file as the file to open.

iCal used to run AppleScripts. Calendar doesn’t, so you have to make them run themselves as applications.

Hi NIgel. That’s what I did try. It won’t allow it.

Does your app work if you double-click it?

OK, things just got strange.

The app creates the file, but it’s empty. But the script actually works when the administrator runs it in the terminal.

I just got this working in the crontab as well and the resulting mysqldump is empty.

Cheers

Hi,

If you’re using a variable in your script, it might not work. ‘do shell script’ starts with a default set of variables.

gl,
kel

Hi there. No variables. Just the do script call.

In any case I can call the script in the terminal using an administrator’s account and it works just fine. Called by the cron and the file is made, but it’s empty.

I’m going to try launchd.

Cheers

No, what I’m saying is that the global variables are different. Try this in AppleScript Editor:

do shell script "set"

Now, try this in Terminal:

Especially the PATH variable is different.

Sure, but that doesn’t explain why the cron has those results. If called by the administrator, then the PATH in set includes mysql’s directories.

Hi daBee,

Do you want a script to create a launch agent in your home library folder? :slight_smile:

gl,
kel

That’s what I’m doing right now.

OK, launchd works calling the script, but the mysqldump file is indeed empty. I should run over to the mysql list to see why this is so.

Cheers