Benches macOS

15

How do I play an audio file on shutdown?

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

I have a .aif file that plays the "auto shutdown sequence in progress" parody from Star Trek.

In classic, I put it into a shutdown folder and it played on shut down. It won't work on Tiger, no such folder.

I don't know anything about scripting and if I did, I don't know where to put the finished script so it activates on shutdown.

I attempted:

tell application "Finder"

activate

select window of desktop

select window of desktop

open document file "autoshutdown.aif" of folder "Desktop" of folder "ttruscott" of folder "Users" of startup disk

select window of desktop

end tell

which on run does open QuickTime but doesn't start to play...

And if it did run, where do I store it?

15 replies

Sign in or join Beachball Help to reply.

  1. 0

    Camelot

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    You're taking a too-literal approach with your script.

    The Finder doesn't need to be involved in this at all. All you're doing with your script is opening some windows (not needed) and telling the Finder to open a document. As you've found there's nothing that actually tells anything to play the sound (for all the Finder knows you could be telling it to open a Word document, or a JPEG image, or any number of other files.

    An alternative approach is to target the application directly. Since you're opening the sound file in QuickTime Player you'd be better off with something like:

    tell application "QuickTime Player"

    play (alias "HD:Users:ttruscott:Desktop:autoshutdown.aif")

    end tell

    The issue you may have is in launching this. The OS will balk at launching a new application (e.g. QuickTime Player) once it's been told to shut down. This may mean that you need to have QuickTime Player running before you initiate the shutdown, which is going to be harder to manage.

  2. 0

    Budgie

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hi Ted

    Maybe you could create a script with a "on quit" handler that will play your .aif file, save it as a application and put it in your log in items, the script will start up when you log in and then when you quit or shut down you Mac it should play your file.

    Budgie

  3. 0

    Ted Truscott1

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Thanks guys,

    I have a little sound program called Play Sound I think I'll use but, I'm afraid I have no idea of how to create an "on quit" hanndler.

    Is there a short course on writing scripts?

    Camelot, thanks for you reffort but it has a 'syntax' error and " file waasn't found" even after I took the path form the CommandI Info. If It worked, I'd try to add an "on quit handler" like Budgie said.

  4. 0

    Budgie

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hi Ted

    try the below saved as a stay open application

    on quit

    tell application "Play Sound"

    play (alias "Macintosh HD:Users:Ted:Desktop:01 Icky Thump 1.aif")

    continue quit

    end tell

    end quit

    Budgie

    Message was edited by: Budgie

    just down loaded "Play Sound" cool little app, cheers

    this may work better?

    on quit

    set soundFile to "Macintosh HD:Users:Ted:Desktop:01 Icky Thump 1.aif" as alias

    tell application "Play Sound"

    play soundFile

    continue quit

    end tell

    end quit

  5. 0

    Ted Truscott1

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I works!!!

    at least

    set soundFile to "Macintosh HD:Users:ttruscott:Desktop:autoshutdown.aif" as alias

    tell application "Play Sound"

    play soundFile

    end tell

    plays the sound! Now I'll add on the "on quit" stuff and test that! OOps - syntax again telling me it expected "end" and got "end tell" instead.

  6. 0

    Ted Truscott1

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Thank you Budgie,

    It worked fine. On start up, an icon appeared in my dock and started bouncing and I had to click it to settle it down but that is a small price to pay.

    If I want to put the sound file somewhere, I just edit in the proper place? And can I store the script itself just anywhere?

  7. 0

    Budgie

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    my pleasure

    yes, just edit the path to you sound file.

    put your script anywhere you wish and then add it to your log in items, for the first time you may need to activate it so it is running before you shut down.

    Budgie

  8. 0

    Ted Truscott1

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    [quote]put your script anywhere you wish and then add it to your log in items, for the first time you may need to activate it so it is running before you shut down.

    Budgie[quote]

    On the test it worked fine but after the re-boot, when I shut down for the night, it did not work.

    By a'ctivate' you mean exactly what?

  9. 0

    Budgie

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    by "activate" I mean start the script, double click on it.

    hmmm, ok, copy and paste the script below into script editor, change the path to suit the path to your .aif file if need be.

    Save the script as a run only, stay open application.

    Double click on the application, to activate it, then when it's activated quit it,

    the sound file should play.

    If the above tests well add the application to your log in items, then double click the application to activate it, then shut down your computer, the script should activate the sound file?

    on quit

    set soundFile to "Macintosh HD:Users:ttruscott:Desktop:autoshutdown.aif" as alias

    tell application "Play Sound"

    play soundFile

    continue quit

    end tell

    end quit

    Budgie

  10. 0

    Ted Truscott1

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I havn't tried this new verson yet as last night the shutdown sequence was stalled twice because the file autoshutdown.aif could not find Play Sound.

    Once I opened Play Sound, it worked. I think the problem may be that Play Sound is a dmg (just another reason to hate the dmg foolishness).

    What about that? (Are you still having fun? I hope so! 🙂 )

  11. 0

    Ted Truscott1

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Perhaps pertinant to my last post is the suggestion from a previous post:

    "This may mean that you need to have QuickTime Player running before you initiate the shutdown, which is going to be harder to manage. "

  12. 0

    Budgie

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    double click the .dmg file for play sound, drag the application "Play Sound"

    to your applications folder from the window presented, now your script wont stall because the application is available.

    try the below set up as previously mentioned, this will activate "Play Sound"

    tell application "Play Sound"

    activate

    end tell

    on quit

    set soundFile to "Macintosh HD:Users:ttruscott:Desktop:autoshutdown.aif" as alias

    tell application "Play Sound"

    play soundFile

    continue quit

    end tell

    end quit

    Budgie

  13. 0

    Ted Truscott1

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Still hanging up:

    is something wrong wih this?

    set soundFile to "Macintosh HD:Users:ttruscott:Applications:autoshutdown.aif" as alias

    or is the path broken between ttruscott and applications?

  14. 0

    Budgie

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    cut and paste this script into script editor, save as a application, drag and drop your .aif file onto the script, the path to your file has now been copied to the clipboard, paste that information into your script, see if the path set up is any different to what you already have.

    on open _theseItems

    set _location to _theseItems as text

    set the clipboard to _location

    display dialog "The path to the item has been copied " & return & ¬

    "to the clipboard." with icon note giving up after 5

    end open

    Budgie

  15. 0

    Ted Truscott1

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    While it didn't play on 'run,' it did play twice on shutdown without hanging up - THANK YOU VERY MUCH!