Copy link to clipboard
Copied
I'd like to play an audio alert once my script finishes running, I looked up some options online, but I can only find reference to how to play sound using javascript and html5.
Solution on Mac:
try{
app.system("afplay /System/Library/Sounds/Glass.aiff")
}catch(e){
};
Copy link to clipboard
Copied
beep();
Copy link to clipboard
Copied
Thanks, but I'm looking to play a sound from a file rather than just the default error noise, any pointers?
Copy link to clipboard
Copied
You could play a music file, as an example.
var music = new File("/E/Music/Country/Sundown.mp3");
if(music.exists) music.execute();
Copy link to clipboard
Copied
Then you should have asked how to play a sound file rather then play and alert.
try{
var Sound = new File("C:/Windows/Media/tada.wav");
Sound.execute();
}catch(e){
alert("Can Not Play Sound");
};
This depends on system file associations. If there is a player associated with the file extension it should open and play the sound. It may also remain open after the sound is over, or may loop playing the sound repeatly
Copy link to clipboard
Copied
Awesome! This is definitely more of the idea, although it opens up windows media player, to play. It would be used in a batch, so I wouldn't necessarily want to have to open a program every time, but it does make sense as I'm unaware if there's a default background player for PC and mac. Otherwise I did find documentation on flash, and in using Window, and adding flash player to it, I'm able to get the desired sound to play. However I tried using a relative path from the script to the swf, and it came back with an error. I had to place the swf on my desktop to test correctly. Is there a way to use relative paths?
win.preview = win.add ('flashplayer',undefined,'~/Desktop/test.swf');
Copy link to clipboard
Copied
You need the full path if it relative to the script you can get the scripts path
alert(File($.fileName).parent.fsName);
Copy link to clipboard
Copied
I tried adding this to the end of the following script, but no sound plays after it finishes. Am I missing something?
for (var i = 0; i < 2; i++) app.doAction("Pixel Crop+Scale Loop","shape");beep();
Copy link to clipboard
Copied
It works for me.
Copy link to clipboard
Copied
Yeah, it's working for me now too. I thnk there was an issue w/ my system sound when I tried it before as I have since rebooted and now get the system alert sound at the end of the script, which is what I assume is supposed to happen.
Copy link to clipboard
Copied
Solution on Mac:
try{
app.system("afplay /System/Library/Sounds/Glass.aiff")
}catch(e){
};