Search code examples
xcodebashapplescriptapplescript-objc

how to run a script while afplay is running


Hello everyone I am wondering how to continue with the script execution while afplay is running? For example...

   do shell script "afplay /song.mp3"
    say "Hello, nice to meet you, what's your name?"

When I execute the code the command "Say" won't be executed until the song stops! Thanks!


Solution

  • In bash you can use:

    #!/bin/bash
    command_name &
    echo "message"
    

    the ampersand will run that command in the background.

    So in applescript, something like this:

    do shell script "afplay /song.mp3 &"
      "echo 'Hello, nice to meet you, what's your name?'"
    

    hope that helps.