# How to play a sound or tone when a program ends?

**URL:** https://discourse.julialang.org/t/how-to-play-a-sound-or-tone-when-a-program-ends/41239
**Category:** General Usage
**Tags:** sound
**Created:** [June 12, 2020, 2:39am UTC](https://discourse.julialang.org/t/how-to-play-a-sound-or-tone-when-a-program-ends/41239 "2020-06-12T02:39:48Z")
**Posts on this page:** 1
**Showing post:** 18

<div class="post-metadata">

### Author: ![josephmarturano](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@josephmarturano](https://discourse.julialang.org/u/josephmarturano)
#### Post date: [June 13, 2020, 12:39am UTC](https://discourse.julialang.org/t/how-to-play-a-sound-or-tone-when-a-program-ends/41239/18 "2020-06-13T00:39:39Z")

</div>

Right, I suspect this is related to spaces in a path with powershell ([see this discussion](https://superuser.com/questions/881019/windows-powershell-doesnt-seem-to-accept-target-paths-with-spaces/881029)). I think the following will catch Windows folders with and without spaces:

````julia
function play_a_tune2(SoundFileName1)
    script = ```\$sound = New-Object System.Media.SoundPlayer\;
                \$sound.SoundLocation = \& \"$SoundFileName1\" \;
                \$sound.Play\(\)```
    run(`powershell /c $script`)
end

````

I tested this with a .wav file with two paths on my Windows 10 machine:

```julia
play_a_tune2("C:\\folder_without_spaces\\elephant.wav")

play_a_tune2("C:\\folder with spaces\\elephant.wav")

```

I hear an elephant with both function calls. Or I could also be going crazy.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-play-a-sound-or-tone-when-a-program-ends/41239)._
