Skip to content

Instantly share code, notes, and snippets.

@yosida95
Last active June 10, 2020 05:49
Show Gist options
  • Save yosida95/287e90436baeb2b4e6e1defa6643ef0a to your computer and use it in GitHub Desktop.
Save yosida95/287e90436baeb2b4e6e1defa6643ef0a to your computer and use it in GitHub Desktop.
Jump VLC position to the beginning of the track and go to next track on the playlist when reached the end of the current track
#!/usr/bin/osascript
on run argv
set startMargin to 55
set stopMargin to 115
if (count of argv) = 0 then
# use the default
else if (count of argv) = 2 then
set startMargin to item 1 of argv
set stopMargin to item 2 of argv
else
return ¬
"[ startMargin=" & startMargin & "] " & ¬
"[ stopMargin=" & stopMargin & " ]"
end if
repeat
tell application "VLC"
set position to current time
set duration to duration of current item
if 0 <= position and startMargin + stopMargin <= duration then
if position < startMargin then
do_log( ¬
"Jump to " & ¬
get_filename() of me & " at " & ¬
(round (startMargin / 60) rounding down) as text & "m " & ¬
(startMargin mod 60) as text & "s") of me
set current time to startMargin
repeat while (current time) < startMargin
delay 0.1
end repeat
else if (duration - position) <= stopMargin then
next
repeat while current time <= 0 or position <= current time
# wait for the track is started
delay 0.1
end repeat
end if
end if
end tell
delay 1
end repeat
end run
on get_filename()
tell application "VLC"
set filename to name of current item
end tell
try
return filename
on error number -2753
return ""
end try
end get_filename
on do_log(txt)
set current_date to current date
log "[" & ¬
year of current_date & "/" & ¬
zeropad(month of current_date as number) & "/" & ¬
zeropad(day of current_date) & " " & ¬
zeropad(hours of current_date) & ":" & ¬
zeropad(minutes of current_date) & ":" & ¬
zeropad(seconds of current_date) & ¬
"] " & ¬
txt
end do_log
on zeropad(txt)
set ret to "0" & txt
set ret_len to (length of ret)
return text (ret_len - 1) through ret_len of ret
end zeropad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment