• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Explorer ,
Feb 14, 2013 Feb 14, 2013

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 14, 2013 Feb 14, 2013

Copy link to clipboard

Copied

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;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 15, 2013 Feb 15, 2013

Copy link to clipboard

Copied

i did this way:

function mSound() {

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

app.doScript(myAppleScript, ScriptLanguage.applescriptLanguage);

}

It works. Great!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 15, 2013 Feb 15, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 26, 2013 Feb 26, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 26, 2013 Feb 26, 2013

Copy link to clipboard

Copied

@-hans-:

Is your example a working applescript line or a javascript line? "do shell script"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 26, 2013 Feb 26, 2013

Copy link to clipboard

Copied

Hi @all,

afPlay should be located at 'usr/bin/'

But there's no need to know this because this applescript line runs it:

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

Here the link to its extensiv 😉 manPage: http://www.manpagez.com/man/1/afplay/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 28, 2013 Feb 28, 2013

Copy link to clipboard

Copied

-hans-,

command

do shell script "afplay " & "Mac:Users:d.belyakov:Dropbox:Beliakov:Sounds:printed2.wav"

tells "Applescript error: AudioFileOpen failed (-43)"

PrntScr,

if launched from Javascript line: word "script" is highlighted and status info - "Expected: while". So no progress in both directions ))


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 28, 2013 Feb 28, 2013

Copy link to clipboard

Copied

The shell can only handle posix path (unix path)

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 21, 2013 Mar 21, 2013

Copy link to clipboard

Copied

LATEST

Yes, if written correctly - afplay does work!

Thanks ))

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines