Hi,

Haven’t played with it much but here’s two sites that should help.

https://www.dssw.co.uk/blog/2010-09-09-how-to-shut-down-your-mac-using-applescript/

for the Shutdown command that actually is reasonably easy to find in the Finder 
Scripting Dictionary.  You need to be careful though as the basic command of:

tell application “Finder”
shut down
end tell

will do just that.  It will shut down your Mac right now, no chance to save or 
close anything.  If you’re lucky, things will open back to the state they were 
upon restart, but you probably would be encouraged to read some of the extra 
parameters available in the blog post.

For the sound, you can look at

http://leancrew.com/all-this/2007/12/playing-sounds-in-applescript/

Info looks fairly understandable.  There’s a link on this page that takes you 
to a out of business software company web-site but if you follow some helpful 
links on that page, you’ll get to the PlaySound app which also seems pretty 
easy to work with.

HTH.

Later...

Tim Kilburn
Fort McMurray, AB Canada

On Mar 30, 2015, at 09:35, 'Chris Blouch' via MacVisionaries 
<macvisionaries@googlegroups.com> wrote:

If you can figure out how to get AppleScript to execute shell commands like 
terminal does you could do

afplay /System/Library/Sounds/Frog.aiff

to play one of the system sounds, or specify the path to any sound file you 
want. afplay uses CoreAudio so it should be able to play most common file 
formats. It also has several options for playback speed, output device etc.

For shutting down the terminal command would be just shutdown followed by 
either -h -s or -r which stand for halt, sleep or restart so to do what you 
want would be

shutdown -h

Note that all running apps will be asked to quit and they may do that or they 
may ask to cancel the shutdown. For example, if you had an unsaved state in an 
app, when it received the Quit request it might prompt you to save or cancel. 
If you chose cancel the App might request the shutdown to be canceled. That 
said, I did find some stuff for invoking AppleScript from terminal which might 
include commands you could use from here:

http://apple.stackexchange.com/questions/103571/using-the-terminal-command-to-shutdown-restart-and-sleep-my-mac

Shut down without showing a confirmation dialog:
osascript -e 'tell app "System Events" to shut down'

Shut down after showing a confirmation dialog:
osascript -e 'tell app "loginwindow" to «event aevtrsdn»'

Restart without showing a confirmation dialog:
osascript -e 'tell app "System Events" to restart'

Restart after showing a confirmation dialog:
osascript -e 'tell app "loginwindow" to «event aevtrrst»'

Log out without showing a confirmation dialog:
osascript -e 'tell app "System Events" to  «event aevtrlgo»'

Log out after showing a confirmation dialog:
osascript -e 'tell app "System Events" to log out'

Go to sleep (AppleScript):
osascript -e 'tell app "System Events" to sleep'

CB

On 3/30/15 6:13 AM, Jürgen Fleger wrote:
> Hi,
> 
> could anyone support me in creating an apple script? It is supposed to shut 
> down the Mac but playing a little sound before. So the stepps could be
> 1. Play sound x in folder y.
> 2. Wait as long as it takes to play the sound, maybe 3 seconds.
> 3. Press CMD + Option + CTRL + Eject. That’s the hotkey to shut down the Mac.
> 
> Would be great if anyone could help me to realize this. I’m able to read but 
> not create them.
> 
> All the best
> Jürgen
> 
> 

-- 
¯\_(ツ)_/¯

-- 
You received this message because you are subscribed to the Google Groups 
"MacVisionaries" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to macvisionaries+unsubscr...@googlegroups.com.
To post to this group, send email to macvisionaries@googlegroups.com.
Visit this group at http://groups.google.com/group/macvisionaries.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"MacVisionaries" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to macvisionaries+unsubscr...@googlegroups.com.
To post to this group, send email to macvisionaries@googlegroups.com.
Visit this group at http://groups.google.com/group/macvisionaries.
For more options, visit https://groups.google.com/d/optout.

Reply via email to