OSX - controlling VLC in background

macOS specific usage questions
mizpulyn
New Cone
New Cone
Posts: 4
Joined: 11 Jun 2009 09:45

OSX - controlling VLC in background

Postby mizpulyn » 08 Apr 2017 11:31

is there a way to issue 2 commands to VLC while the app is playing but not in focus (its is not active app but running in background)

VERY SHORT BACKWARDS JUMP
VERY SHORT FORWARD JUMP

normaly when VLC is in front (active app) i can use keyboard shortcuts to jump back and forth

but iam doing a lot of TRANSCRIBING WORK... i play audio with VLC in background and text editor in foreground and iam typing the text

often i need to foward 2-3 words back

i know there is option to use MEDIA KEYS on Macbook

<< backward >|| play >> forward

and i also know that when you press and hold those MEDIA KEYS you can rewind

but its TOO FAST... super short press on the MEDIA KEYS rewinds by almost a minute...

mizpulyn
New Cone
New Cone
Posts: 4
Joined: 11 Jun 2009 09:45

Re: OSX - controlling VLC in background

Postby mizpulyn » 08 Apr 2017 13:40

wow i actually figured it out myself :) but dont ask me for exact step by step id go mad trying to explain this...

iam using combination of KeyRemap4MacBook with AppleScript

its a silly workaround, iam not really controlling VLC ***IN BACKGROUND*** i do have to switch from text editor to vlc and back but it takes 1/50th of second thanks to applescript...

1) vlc is playing audio file in background while iam transcribing text into text editor in foreground
2) KeyRemap4MacBook is setup in such way that if i press a key F7, F8, F9 KeyRemap4MacBook triggers an AppleScript command that momentarily switches to VLC, issues a keyboard shortcut for one of these:

VERY SHORT BACKWARDS JUMP (set to left arrow in vlc)
PAUSE/PLAY (set to spacebar in vlc)
VERY SHORT FORWARD JUMP (set to right arrow in vlc)

than switches immediatelly back to last app - in my case the text editor

the two aplication windows quiclky flash back and forth but it only takes 1/50th of second and because i use F7, F8, F9 i dont loose cursor focus or selection in the text editor (since function keys do not enter any ASCI characters or anything)

below is sample script (private.xml) for KeyRemap4MacBook but you have to figure it out yourself (see above for shortcuts i have setup in VLC for each function)

as you can see below when iam inside VLC i use left arrow, right arrow, spacebar directly to jump back and forth in file
and when iam outside VLC (VLC in background) i use F7, F8, F9 to trigger those same VLC shortcuts for me using AppleScript

<?xml version="1.0"?>
<root>

<vkopenurldef>
<name>KeyCode::VK_OPEN_URL_JXA_keystroke_back</name>
<url type="shell">
osascript -e '
tell application "VLC2.2.1-64"
activate
end tell
tell application "System Events"
tell process "VLC"
key code 123
key code 48 using command down
end tell
end tell
'
</url>
</vkopenurldef>

<vkopenurldef>
<name>KeyCode::VK_OPEN_URL_JXA_keystroke_forward</name>
<url type="shell">
osascript -e '
tell application "VLC2.2.1-64"
activate
end tell
tell application "System Events"
tell process "VLC"
key code 124
key code 48 using command down
end tell
end tell
'
</url>
</vkopenurldef>

<vkopenurldef>
<name>KeyCode::VK_OPEN_URL_JXA_keystroke_space</name>
<url type="shell">
osascript -e '
tell application "VLC2.2.1-64"
activate
end tell
tell application "System Events"
tell process "VLC"
keystroke space
key code 48 using command down
end tell
end tell
'
</url>
</vkopenurldef>

<appdef>
<appname>vlc</appname>
<equal>org.videolan.vlc</equal>
</appdef>

<item>
<name>Slow Fast inside VLC</name>
<identifier>Slow Fast inside VLC</identifier>
<only>vlc</only>
<autogen>__KeyToKey__ KeyCode::F9, KeyCode::CURSOR_RIGHT</autogen>
<autogen>__KeyToKey__ KeyCode::F8, KeyCode::SPACE</autogen>
<autogen>__KeyToKey__ KeyCode::F7, KeyCode::CURSOR_LEFT</autogen>
</item>

<item>
<name>Slow Fast outside VLC</name>
<identifier>Slow Fast outside VLC</identifier>
<not>vlc</not>
<autogen>__KeyToKey__ KeyCode::F9, KeyCode::VK_OPEN_URL_JXA_keystroke_forward</autogen>
<autogen>__KeyToKey__ KeyCode::F8, KeyCode::VK_OPEN_URL_JXA_keystroke_space</autogen>
<autogen>__KeyToKey__ KeyCode::F7, KeyCode::VK_OPEN_URL_JXA_keystroke_back</autogen>
</item>

</root>


i also have similarily setup keyboard shortcuts for fine speed UP and DOWN to slow down speach when transcribing... using same principal as above...

VLC become a transcribing / learning / audio courses WORKHORSE even on OSX without global shortcuts

hope it will show you in the right direction, please dont ask for elaboration... this must be enough... it took me 2 hours to figure out from scratch using google so its not that complicated...

auralarch
Blank Cone
Blank Cone
Posts: 38
Joined: 26 Nov 2012 01:12
VLC version: 2.2.6
Operating System: Mac OS, Win7 x64
Location: US Capital region

Re: OSX - controlling VLC in background

Postby auralarch » 21 Jul 2017 00:43

Actually, VLC has its own Applescript dictionary! Which means you really can control VLC in the background using Applescript! If you open up the Applescript editor and type {command + shift} L, the Library window will open or come to the front. Double click on VLC in that list and a new window will open describing all the actions controllable with Applescript and how to use them. You probably won't be able to do everything that you want to do, but I've found this extremely useful.
You can get information about whether VLC is playing, and about the current item if so- such as the playback position and some metadata. Most of the basic controls are scriptable. However, some are missing; most notably (for me) are controls for navigating "chapters" (which I have invested quite a bit of time to add to many of my media files; some manually, but the chapter points for many TV shows & movies can be found online and downloaded and they can even be added to most media files without re-encoding!), controls for manipulating playback speed (that could be really awesome because it could potentially make it possible to set the playback speed to custom rates—not just trigger the existing shortcuts. This is already possible to some extent with the slider in the menu but that is a very awkward and poorly implemented UI control which is all but a useless waste of space & source of frustration to anyone attempting to use it. Those are the main things that I wish were scriptable, audio sync would also be a great help (especially since the keyboard shortcut I've setup does not work consistently on my Mac—which I haven't been able to figure out why at all, other hotkeys work but adjusting the audio sync only works sporatically...).

Here is a little script that sends VLC the keyboard shortcut I designated to advance to the next chapter IF VLC is currently playing. If the file doesn't have chapters then the script tells VLC to jump ahead by the 3rd (next to largest) configurable number of seconds. It also returns the focus to whatever application was active to begin with (if not VLC).

Code: Select all

tell application "VLC" if playing is true then set playTime to (current time as integer) if application "VLC" is frontmost then tell application "System Events" to key code 124 using {option down} # Option + RightArrow else set old to (path to frontmost application as text) activate application "VLC" tell application "System Events" to key code 124 using {option down} # Option+RightArrow activate application old end if if current time is not greater than playTime then tell application "VLC" to step forward 3 end if end if end tell
Here's another example which I have setup to be triggered by the shortcut which I previously had configured in VLC to play the previous item in the playlist. My script actually restarts the current item as long as it has played for at least 15 seconds (a percentage of the total track length could be setup instead of course), otherwise (if playback hasn't reached 15 seconds) it plays the previous item. So if I press it twice it will play the previous item if the current one is past 15 seconds. I also have it configured to stay paused (re-pause playback) after altering the current playback location instead of starting to play—if it's paused to begin with.

Code: Select all

tell application "VLC" if playing is true then tell application "VLC" if current time is greater than 15 then tell application "VLC" to set current time to 1 else tell application "VLC" to previous end if end tell else tell application "VLC" if current time is greater than 15 then tell application "VLC" to set current time to 1 tell application "VLC" to play else tell application "VLC" to previous tell application "VLC" to play end if end tell end if end tell

I'm not surprised that you weren't aware that VLC can actually be controlled with Applescript because there is very little (if any mention of it) in the documentation. That's unfortunate because I think it would be used more if they advertised it more/better—and it is such a convenient and useful feature!

Anyway, I hope that helps someone get started and use VLC's Applescript abilities in their setup. It is definitely a great way to add global hotkeys for VLC on a Mac for the functions available...
Computers:
ASUS Sabertooth X58 Core i7 930 (ALC892 onboard audio), 24GB DDR3, Sapphire Radeon HD 6870; Gigabyte X58A-UD3R (ALC898) Core i7 920, 18GB DDR3, XFX Radeon HD 5770; MacPro5,1 8GB RAM; Toshiba Satellite L640
OSes:
Mac OS X 10.8.5; Windows 7 Ultimate (x64)

auralarch
Blank Cone
Blank Cone
Posts: 38
Joined: 26 Nov 2012 01:12
VLC version: 2.2.6
Operating System: Mac OS, Win7 x64
Location: US Capital region

Re: OSX - controlling VLC in background

Postby auralarch » 21 Jul 2017 20:42

is there a way to issue 2 commands to VLC while the app is playing but not in focus (its is not active app but running in background)

VERY SHORT BACKWARDS JUMP
VERY SHORT FORWARD JUMP

...
The short, concise answer to this question is:

Yes! There is a way!

Code: Select all

tell application "VLC" to step backward 1

Code: Select all

tell application "VLC" to step forward 1
As shown above you can check if VLC is playing, but I forgot to mention that you can also check if VLC is even running—although I do this by other means because I found that there seems to be a glitch somewhere that causes VLC to launch when checking if it's running... (It seems to me that this is sort of a logistical circular error since the command to check if VLC is running is part of the VLC Applescript library; therefore it has to launch VLC to check—at which point "Yes, it's running")
Basically, I just wanted to point out that VLC will launch if you use any code from its dictionary in an Applescript which may not always be desirable. And there are other ways to determine if VLC is running using Bash & Applescript.
Computers:
ASUS Sabertooth X58 Core i7 930 (ALC892 onboard audio), 24GB DDR3, Sapphire Radeon HD 6870; Gigabyte X58A-UD3R (ALC898) Core i7 920, 18GB DDR3, XFX Radeon HD 5770; MacPro5,1 8GB RAM; Toshiba Satellite L640
OSes:
Mac OS X 10.8.5; Windows 7 Ultimate (x64)

brandelune
New Cone
New Cone
Posts: 4
Joined: 28 Oct 2017 15:24

Audio transcription with VLC (Re: OSX - controlling VLC in background)

Postby brandelune » 28 Oct 2017 15:34

I had a similar issue 4 years ago, that I solved with Applescript+Automator+system-wide shortcuts.

I wrote an article about that then, and as I was updating it today I came looking for reference on the differences in Applescript support in VLC between the version I was using then and the current version, and I found this question.

I understand that there already are answers, but let me link to the article that I eventually posted today.

In the article I first use only bundled software and at the end use VLC as a replacement for QuickTime Player since it solves a number of issues that QTP has. The code is trivial, but I think it globally shows how to create nicely integrated solutions with very little, thanks to VLC's Applescript support.

https://mac4translators.blogspot.jp/201 ... -free.html


Return to “VLC media player for macOS Troubleshooting”

Who is online

Users browsing this forum: No registered users and 14 guests