Applescript to start headless Vuze (Azureus)?

Discussion in 'Mac Apps and Mac App Store' started by midwich, Aug 20, 2010.

  1. midwich macrumors member

    Joined:
    Jun 12, 2007
    #1
    Hi there,
    I've been drive quite mad trying to work out the correct syntax for activating a shell script in Applescript to start Vuze in headless mode and would appreciate any advice.

    If I just paste the following into Terminal, it works fine:

    java -XstartOnFirstThread -Dazureus.install.path="/Applications/Vuze.app/" -Dazureus.config.path="$HOME/Library/Application Support/Vuze/" -Duser.dir="/Applications/" -Dazureus.console.multiuser=1 -jar /Applications/Vuze.app/Contents/Resources/Java/Azureus2.jar --ui=console

    [taken from boonlen's post of Sept 5 2009]



    BUT if I try the following equivalent in Applescript, it doesn't:

    set install_path to "Macintosh_HD/Applications/Vuze.app/"
    set config_path to "Macintosh_HD/Users/gavin/Library/Application Support/Vuze/"
    set user_dir to "Macintosh_HD/Applications/"
    set azureus_jar to "/Macintosh_HDApplications/Vuze.app/Contents/Resources/Java/Azureus2.jar"

    do shell script "java -XstartOnFirstThread -Dazureus.install.path= " & install_path & " -Dazureus.config.path= " & config_path & " -Duser.dir= " & user_dir & " -Dazureus.console.multiuser=1 -jar " & azureus_jar --ui=console"



    I get this error message when I try to run the applescript:

    Exception in thread "main" java.lang.NoClassDefFoundError: Macintosh_HD/Applications/Vuze/app/

    Any ideas?


    PS the reason I want to start Vuze this way is to be able to script the removal of completed torrents.
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    Well, there's a typos in this line,
    Code:
    set azureus_jar to "/Macintosh_HDApplications/Vuze.app/Contents/Resources/Java/Azureus2.jar"
    Missing the / in front of Applications. Also, you don't need the Macintosh_HD bit at all, just do /Applications/...

    You'll likely need to use the "quoted form of" syntax on your paths when putting them together so things are escaped appropriately.
     
  3. midwich thread starter macrumors member

    Joined:
    Jun 12, 2007
    #3

    Thanks very much for such a fast response! I've changed the script to read:

    set install_path to "Macintosh_HD/Applications/Vuze.app/"
    set config_path to "Macintosh_HD/Users/gavin/Library/Application Support/Vuze/"
    set user_dir to "Macintosh_HD/Applications/"
    set azureus_jar to "/Macintosh_HD/Applications/Vuze.app/Contents/Resources/Java/Azureus2.jar"


    do shell script "java -XstartOnFirstThread -Dazureus.install.path= " & quoted form of install_path & " -Dazureus.config.path= " & quoted form of config_path & " -Duser.dir= " & quoted form of user_dir & " -Dazureus.console.multiuser=1 -jar " & quoted form of azureus_jar --ui=console"



    It complies fine, but unfortunately I get the same error when I try to run it.

    PS have got rid of Macintosh_HD references too.
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    Try assigning the do shell script contents to a variable first and do a display dialog on it to see the exact string it is trying to execute.

    Code:
    set _script to "java -XstartOnFirstThread -Dazureus.install.path= " & quoted form of install_path & " -Dazureus.config.path= " & quoted form of config_path & " -Duser.dir= " & quoted form of user_dir & " -Dazureus.console.multiuser=1 -jar " & quoted form of azureus_jar --ui=console"
    display dialog _script
     
  5. Mal macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #5
    AppleScript typically requires POSIX file paths, though you can convert it on the fly. Might be easiest just to change your path to use : instead of /. Thus,

    Code:
    set install_path to "Macintosh_HD:Applications:Vuze.app"
    and so on. I'd leave the Macintosh_HD part there. BTW, is your drive actually named Macintosh_HD or is it Macintosh HD, because that's significant. I ask because the default is Macintosh HD, without the underscore, but obviously you may have changed it yourself.

    jW
     
  6. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #6
    That's true if the file paths are being used for say Finder, but he's passing them to Terminal, which needs slashes.
     
  7. midwich thread starter macrumors member

    Joined:
    Jun 12, 2007
    #7
    Thanks very much for this, this is the result returned:

    display dialog "java -XstartOnFirstThread -Dazureus.install.path= '/Applications/Vuze.app/' -Dazureus.config.path= '/Users/gavin/Library/Application Support/Vuze/' -Duser.dir= '/Applications/' -Dazureus.console.multiuser=1 -jar '/Applications/Vuze.app/Contents/Resources/Java/Azureus2.jar'"


    Copied and pasted it into Terminal and definitely doesn't work. Differences between this output and the working version that I can see are that many of the double quotes are missing, and the ' --ui=console' bit originally at the end is also not there.
     
  8. midwich thread starter macrumors member

    Joined:
    Jun 12, 2007
    #8
    Thanks for this, I changed the script to read:

    set install_path to quoted form of the POSIX path of "Macintosh_HD:Applications:Vuze.app/"
    set config_path to quoted form of the POSIX path of "Macintosh_HD:Users:gavin:Library:Application Support:Vuze:"
    set user_dir to quoted form of the POSIX path of "Macintosh_HD:Applications/"
    set azureus_jar to quoted form of the POSIX path of "Macintosh_HD:Applications:Vuze.app:Contents:Resources:Java:Azureus2.jar"

    set _script to "java -XstartOnFirstThread -Dazureus.install.path= " & install_path & " -Dazureus.config.path= " & config_path & " -Duser.dir= " & user_dir & " -Dazureus.console.multiuser=1 -jar " & azureus_jar --ui=console"
    display dialog _script


    do shell script "java -XstartOnFirstThread -Dazureus.install.path= " & install_path & " -Dazureus.config.path= " & config_path & " -Duser.dir= " & user_dir & " -Dazureus.console.multiuser=1 -jar " & azureus_jar --ui=console"





    The dialog output reads:

    display dialog "java -XstartOnFirstThread -Dazureus.install.path= '/Applications/Vuze.app:' -Dazureus.config.path= '/Users/gavin/Library/Application Support/Vuze/' -Duser.dir= '/Applications:' -Dazureus.console.multiuser=1 -jar '/Applications/Vuze.app/Contents/Resources/Java/Azureus2.jar'"





    I think that's the same as before, oh well! If I put the 'do shell script' line first, I get this output as previously:

    Exception in thread "main" java.lang.NoClassDefFoundError: /Applications/Vuze/app:



    Yes I changed the name of the HD some while ago to include the underscore as I tend to have enough trouble with scripts without dealing with spaces too! The occasional obscure app may also have trouble with the space I've found and not necessarily be clear that that's the problem, so better safe than sorry.
     
  9. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #9
    You had a quote imbalance, which caused the end to get cut out. Try this,

    Code:
    set install_path to "/Applications/Vuze.app/"
    set config_path to "/Users/gavin/Library/Application Support/Vuze/"
    set user_dir to "/Applications/"
    set azureus_jar to "/Applications/Vuze.app/Contents/Resources/Java/Azureus2.jar --ui=console"
    
    do shell script "java -XstartOnFirstThread -Dazureus.install.path=" & quoted form of install_path & " -Dazureus.config.path=" & quoted form of config_path & " -Duser.dir=" & quoted form of user_dir & " -Dazureus.console.multiuser=1 -jar " & azureus_jar
    I can't test it as I don't have Vuze. I fixed the quotes and removed some potentially troublesome spaces.
     
  10. midwich thread starter macrumors member

    Joined:
    Jun 12, 2007
    #10
    That works! Fantastic, thank you so much for being so patient I really appreciate it :) :)
     

Share This Page