Skip to main content
Inspiring
February 15, 2013
Question

can i add a sound to js-script [CS6-js/applecsript]?

  • February 15, 2013
  • 2 replies
  • 2001 views

Now i approached to squeezze out a sound from Mac by using 3rd part app:

tell application "Play Sound"

          play "Mac:Users:me:Sounds:copied.wav"

end tell

Can i attach this scpt to my js-script in any way?

Thanks in advance.

This topic has been closed for replies.

2 replies

BeliakovAuthor
Inspiring
February 15, 2013

i did this way:

function mSound() {

var myAppleScript = ("/Users/me/my misc/myscripting/mSound.applescript");

app.doScript(myAppleScript, ScriptLanguage.applescriptLanguage);

}

It works. Great!

Inspiring
February 15, 2013

Hi ,

MacOsx BuiltIn-Player is 'afPlay'. So there is no need for thirdPartApp

do shell script "afplay " & quoted form of POSIX path of ("Here:a:macpath!")

Nice Day

BeliakovAuthor
Inspiring
February 26, 2013

OK. But so far my Mac didn't found his afPlayer (( OK. So i shall use third-part app.

MrTIFF
Participating Frequently
February 15, 2013

The key is to put your appleScript into a string, and call the app.doScript() function.

Here's an example, by Kasyan Servetsky:

// Written by Kasyan Servetsky

var myDisk = GetStartUpDisk();

alert("The name of my start up disk is \"" + myDisk + "\"");

function GetStartUpDisk() {

    if (File.fs == "Macintosh") {

        var myScript = 'tell application \"Finder\"\r'

        myScript += 'set myStartUpDisk to get name of startup disk\r';

        myScript += 'end tell\r';

        myScript += 'tell application \"Adobe InDesign CS' + ((parseInt(app.version.substr(0, 1)) - 2) + "") + '\"\r';

        myScript += 'tell script args\r';

        myScript += 'set value name \"myScriptArgument\" value myStartUpDisk\r';

        myScript += 'end tell\r';

        myScript += 'end tell\r';

        app.doScript(myScript, ScriptLanguage.applescriptLanguage);

        var myStartUpDisk = app.scriptArgs.getValue("myScriptArgument");

    }

    else if (File.fs == "Windows")  {

        var myStartUpDisk = String(Folder.system).charAt(1);

    }

    return myStartUpDisk;

}