Jump to content

Starting one script after another with pause


Recommended Posts

Hi,

 

i'm quite new to workflows - just have installed some ready made ones but only did a simple one myself. This simple one until now just started VLC video player with a parameter to a special Playlist-URL.

I now want to extend this workflow and have it send a WOL (wake on lan) packet first, then wait X seconds (still have to test how long to wait ideally) and then start VLC and additionally call a URL in Chrome.

 

I already have the python script to send the WOL packet and that works. Now i need to find out how to execute my VLC command. Until now i did this via the "Run script" module with /bin/bash selected as language and it looked like this:

/Applications/VLC.app/Contents/MacOS/VLC http://192.168.88.200:3000/channels.m3u

most probably there's a better way to do this but anyhow i need to know how to put these commands in a row with a pause in between.

 

Can anyone tell me?

 

Thanks!

Frank

 

Link to comment

In Python: 

from time import sleep
sleep(2) # seconds
In bash: 

sleep 2 # seconds
To determine if the host is already online, you can try pinging it.

Bash: 

ping -o -t 1 192.168.0.1
if [[ $? -gt 0 ]]; then
  echo "Offline"
else
  echo "Online"
fi
-o means exit after receiving one response, -t 1 means 1 second timeout.

Python:

import subprocess
retcode = subprocess.call(['ping', '-o', '-t', '1', '192.168.0.1'])
if retcode > 0:
    print('Offline')
else:
    print('Online')
How's that for you? Edited by deanishe
Link to comment

Thanks deanishe,

 

that works great for me. My bash script within the workflow now looks like this:

 

 

ping -o -t 1 192.168.xx.200

if [[ $? -gt 0 ]]; then
  python /Users/xxx/scripts/wol.py
  sleep 40
fi
 
/Applications/VLC.app/Contents/MacOS/VLC http://192.168.xx.200:3000/channels.m3u --sout-deinterlace-mode=blend

 

the python script is this one (just in case someone cares) 

 

 

#!/usr/bin/env python

# wol.py

 

import socket

import struct

 

def wake_on_lan(macaddress):

    """ Switches on remote computers using WOL. """

 

    # Check macaddress format and try to compensate.

    if len(macaddress) == 12:

        pass

    elif len(macaddress) == 12 + 5:

        sep = macaddress[2]

        macaddress = macaddress.replace(sep, '')

    else:

        raise ValueError('Incorrect MAC address format')

 

    # Pad the synchronization stream.

    data = ''.join(['FFFFFFFFFFFF', macaddress * 20])

    send_data = ''

 

    # Split up the hex values and pack.

    for i in range(0, len(data), 2):

        send_data = ''.join([send_data,

                             struct.pack('B', int(data[i: i + 2], 16))])

 

    # Broadcast it to the LAN.

    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

    sock.sendto(send_data, ('<broadcast>', 7))

 

 

if __name__ == '__main__':

    # Use macaddresses with any seperators.

    # wake_on_lan('0F:0F:DF:0F:BF:EF')

    # wake_on_lan('0F-0F-DF-0F-BF-EF')

    # or without any seperators.

    wake_on_lan('12-34-56-78-90') # enter MAC-address here

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...