Use AppleScript to open VLC playlist at set volume?

Discussion in 'Mac Programming' started by shenti, Dec 4, 2015.

  1. shenti macrumors newbie

    Joined:
    Dec 4, 2015
    #1
    Hi there!

    I'm a complete AppleScript newbie. The only reason I'm trying to use it now is because I want to use VLC as my alarm clock to wake me up with a set playlist and volume every morning. The simplest way I've found on Google to do this is to make iCal run a script. I found a script for iTunes online and modified it a bit to suit my needs:

    tell application "VLC (2.0.3)"
    activate
    set
    sound volume to 100
    play "/Users/Adriana/Desktop/Favs.m3u"
    end tell

    (Favs.m3u is the name of the playlist I want it to play and it's located on my desktop. The volume I want will be very high, but I might have to experiment with this because I don't want to wake up with a heart attack :p )

    When I run the script I get this error:

    error "The variable volume is not defined." number -2753 from "volume"

    Can anyone tell me what I'm doing wrong, i.e. correct the script so I can use it? I'm using OSX 10.7.5 if that helps.

    I know eventually I would like to learn AppleScript, but right now I'm just looking for he quick fix to start using VLC as my alarm... Any help would be nice :)
     
  2. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #2
    This is what you want (assuming you want the volume at 100%).

    Code:
    set volume output volume 100
     
  3. shenti thread starter macrumors newbie

    Joined:
    Dec 4, 2015
    #3
    Thanks Weaselboy. It kind of worked, but the file is not opening. I get this from VLC: see attached image


    If I choose the right file through that VLC window then it opens at the right volume, but I need it to open directly from iCal so it can work as an alarm... any ideas on what else could be wrong? Code looks like this:

    tell application "VLC (2.0.3)"
    activate
    set volume
    output volume 100
    play "/Users/Adriana/Desktop/Favs.m3u"
    end tell
     

    Attached Files:

  4. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #4
    From looking at the Applescript documentation for VLC, it looks like you have to tell it what file/playlist to open before playing. So I think this would work.

    Code:
    tell application "VLC"
      OpenURL "file://~/Desktop/test/Favs.m3u"
      play
    end tell
     
  5. shenti thread starter macrumors newbie

    Joined:
    Dec 4, 2015
    #5
    hmmm I don't get the window anymore but an error from VLC... see attached image
     

    Attached Files:

  6. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #6
    Try :

    Code:
    set myPlaylist to choose file
    tell application "VLC"
    open myPlaylist
    --or without the set myPlaylist statement
    --open alias "path:to:your:playlist:whatever.m3u"
    end tell
     
  7. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #7
    If you just right click on the file in Finder then open it with VLC, does it work then (just to check the playlist file).
     
  8. shenti thread starter macrumors newbie

    Joined:
    Dec 4, 2015
    #8
    Thanks for all the help Weaselboy! I took your tips and at the beginning they didn't work: I got the playlist to open but not to play. Then I had the crazy idea of breaking up the command into smaller pieces and it worked! In the end the script looks like this:

    tell application "VLC (2.0.3)"
    activate
    set volume
    output volume 40
    end tell

    tell application "VLC (2.0.3)"
    open "/Users/Adriana/Desktop/Favs.m3u"
    end tell

    tell application "VLC (2.0.3)"
    play "/Users/Adriana/Desktop/Favs.m3u"
    end tell

    I have no idea why this is because I'm a complete beginner in Apple Script, but I'm really happy I can use my iCal as a personalized alarm clock now :)

    Thanks again!! :)
     

Share This Page