private static String[] createOSAScriptCommand(String playlist,File[] files){
  List<String> command=new ArrayList<String>();
  command.add("osascript");
  command.add("-e");
  command.add("tell application \"Finder\"");
  for (int i=0; i < files.length; i++) {
    File f=files[i];
    String path=f.getAbsolutePath();
    command.add("-e");
    command.add("set hfsFile" + i + " to (POSIX file \""+ path+ "\")");
  }
  command.add("-e");
  command.add("set thePlaylist to \"" + playlist + "\"");
  command.add("-e");
  command.add("tell application \"iTunes\"");
  command.add("-e");
  command.add("launch");
  command.add("-e");
  command.add("if not (exists playlist thePlaylist) then");
  command.add("-e");
  command.add("set thisPlaylist to make new playlist");
  command.add("-e");
  command.add("set name of thisPlaylist to thePlaylist");
  command.add("-e");
  command.add("end if");
  for (int i=0; i < files.length; i++) {
    command.add("-e");
    command.add("add hfsFile" + i + " to playlist thePlaylist");
  }
  command.add("-e");
  command.add("end tell");
  command.add("-e");
  command.add("end tell");
  return command.toArray(new String[command.size()]);
}

private static String [ ] createOSAScriptCommand ( String playlist , File [ ] files ) { List < String > command = new ArrayList < String > ( ) ; command . add ( "osascript" ) ; command . add ( "-e" ) ; command . add ( "tell application \"Finder\"" ) ; for ( int i = 0 ; i < files . length ; i ++ ) { File f = files [ i ] ; String path = f . getAbsolutePath ( ) ; command . add ( "-e" ) ; command . add ( "set hfsFile" + i + " to (POSIX file \"" + path + "\")" ) ; } command . add ( "-e" ) ; command . add ( "set thePlaylist to \"" + playlist + "\"" ) ; command . add ( "-e" ) ; command . add ( "tell application \"iTunes\"" ) ; command . add ( "-e" ) ; command . add ( "launch" ) ; command . add ( "-e" ) ; command . add ( "if not (exists playlist thePlaylist) then" ) ; command . add ( "-e" ) ; command . add ( "set thisPlaylist to make new playlist" ) ; command . add ( "-e" ) ; command . add ( "set name of thisPlaylist to thePlaylist" ) ; command . add ( "-e" ) ; command . add ( "end if" ) ; for ( int i = 0 ; i < files . length ; i ++ ) { command . add ( "-e" ) ; command . add ( "add hfsFile" + i + " to playlist thePlaylist" ) ; } command . add ( "-e" ) ; command . add ( "end tell" ) ; command . add ( "-e" ) ; command . add ( "end tell" ) ; return command . toArray ( new String [ command . size ( ) ] ) ; }
constructs and returns a osascript command .
