Newbie needs help with basic shutdown script

Hi there,

I’m a noob. Be gentle. :slight_smile:

Basically I’ve been fiddling around with Applescript, trying to get it to automate some of the minor and annoying tasks in my studio. Specifically, I use a program called Vienna Ensemble Pro, and I’m trying to write a script that will a) Quit the program, b) select the option ‘Don’t Save’ in the subsequent window, c) wait two minutes, and then d) shut down the computer.

So far, I can’t get past step B! I’ve been Googling and searching the forum, trying to figure out what I’m doing wrong, but I just can’t seem to figure it out. So believe me when I say that I tried searching and such, but as a last resort I’m presenting my issue here.

Here’s all I have so far:

tell application “Vienna Ensemble Pro”
quit
end tell
[something to select ‘Don’t Save’]
delay 120
tell application Finder to shut down
end tell

So as you can see, the part that I’m having trouble with is step b. There are three buttons: “Don’t Save”, “Cancel” and “Save” (the last of which is the blue-highlighted one). I can’t, for the life of me, figure out how to select “Don’t Save”. I tried various permutations of ‘click button 1 of window 1’, but I get various error messages.

Any idea what I’m doing wrong here?

Browser: Safari 531.9
Operating System: Mac OS X (10.5)

How about:

tell application "Vienna Ensemble Pro"
	close every document saving no
	quit
end tell
tell application "Finder" to shut down

Finder’s ‘shut down’ is in it’s ‘legacy suite’, so it may disappear without warning.

Use System Event’s version instead.

Hello.

That would be


tell application "System Events" to shut down

Thanks guys. Unfortunately this isn’t working either. It gives me an AppleScript Error saying ‘Vienna Ensemble Pro got an error: every document doesn’t understand the close message.’ Any other ideas?

Hello

First of all: I have no experience with that app.
But try:


tell application "Vienna Ensemble Pro"
	set open_docs to (get its every document I
	repeat with aDoc in open_docs
		tell aDoc to close saving no
	end repeat
	quit
end tell
tell application "Finder" to shut down


Hopes this helps.
I’t would help us helping you if you could copy what it says about the close command from its dictionary, which
can be found via Library in the AppleScript Editor

Hey McUsr,

When I try to compile that scriplet, it gives me a syntax error: “Expected ‘from’, etc. but found identifier.”

But moreover, when I go to the Library and add the Vienna Ensemble Pro app, I get an error message that says 'Unable to add the application or extension because it is not scriptable."

I suppose that’s my answer? That this simply isn’t going to work?

Thanks for all your help,

Chris

Hello

I’ll come back to you with “shutdown” script tomorrow, it is a tad late.
It is one, which asks you to confirm that you have saved what is to be saved, and if you don’t answer in 10 seconds,
(after a chime), it will kill it anyway. -Just so you have a chance to saving work. But this is totally on your own responsibility.

Would you like such a solution?

He ment:

tell application "Vienna Ensemble Pro"
	set open_docs to (get its every document)
	repeat with aDoc in open_docs
		tell aDoc to close saving no
	end repeat
	quit
end tell
tell application "Finder" to shut down

With this one, I get 'Vienna Ensemble Pro got an error: Can’t get every document."

I’m beginning to think it’s hopeless!

Sure, yeah… that sounds good. Does it just kill everything by force quitting, or does it still go through a regular quit routine? Because Vienna Ensemble Pro can take up to a minute to quit, so I need to put some delay in there before the final shut down command.

Thanks for your help, again.

Hello.

You may try this, it might however not work if there are unsaved documents. I’m not sure about that. Try it and come back if it doesn’t work, and then state wether there were open documents in it or any other.
(It ignores any unsaved documents in TextEdit). You may as a matter of fact kill every process which have unsaved documents, but you really wouldn’t do that because one time or another that would save your bacon so to speak.


set appName to (quoted form of "Vienna Ensemble Pro")
do shell script "killall " & appName
repeat
	delay 5
	if not livingProcess(appName) then exit repeat
end repeat
tell application "Finder" to shut down

on livingProcess(qtdProcNameAsText)
	set cmd to "echo"
	set pipe to "`ps ax | grep \"" & qtdProcNameAsText & "\" | grep -v grep | awk '{ print $1 }'  `"
	set theRes to do shell script cmd & space & pipe
	if theRes is "" then
		return false
	else
		return true
	end if
end livingProcess

tell application "Vienna Ensemble Pro"
        try
	     close every document without saving
        end try
	quit
end tell
tell application "Finder" to shut down

Does this work? I’m curious. It’d be helpful to see “Vienna Ensemble Pro’s” apple event dictionary.

That totally worked! Thanks so much!

Is the way that it ‘kills’ the application similar to a Force Quit? I wonder if there’s any chance that it will be somehow bad for the application.

Also, and this is probably the wrong forum for this… but does anyone know if there’s a way to activate this script remotely from another Mac… perhaps using a Terminal script?

Thanks Dylan! This helped me out in an app I was working on… :smiley: