FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister   ProfileProfile    Log inLog in   RSS Feed

VLC script
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Salling Software Forums Forum Index -> Scripting Salling Clicker for Mac
View previous topic :: View next topic  
Author Message
Mr_London
Newbie


Joined: 27 Oct 2005
Posts: 3

PostPosted: Tue Oct 02, 2007 11:05 am    Post subject: VLC script Reply with quote

how can i set salling clicker to pause VLC when on phone ?
Back to top
View user's profile Send private message
salling
Site Admin


Joined: 27 Jul 2004
Posts: 7498
Location: Stockholm, Sweden

PostPosted: Tue Oct 02, 2007 12:11 pm    Post subject: Re: VLC script Reply with quote

You cannot. Such a feature requires VLC to advertise its current player status, which it doesn't. I've suggested to the VLC guys that it'd be useful to boost the scriptability of their app, but nothing seems to have come out of it yet.

Best.
--
Jonas

[quote="Mr_London"]how can i set salling clicker to pause VLC when on phone ?[/quote]
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Mr_London
Newbie


Joined: 27 Oct 2005
Posts: 3

PostPosted: Tue Oct 02, 2007 12:16 pm    Post subject: Re: VLC script Reply with quote

thanks Jonas
hopefully something can be sorted in future,
what about quicktime pausing during a phone call?


[quote="salling"]You cannot. Such a feature requires VLC to advertise its current player status, which it doesn't. I've suggested to the VLC guys that it'd be useful to boost the scriptability of their app, but nothing seems to have come out of it yet.

Best.
--
Jonas
Back to top
View user's profile Send private message
maelcum
Junior Member


Joined: 09 Dec 2007
Posts: 35

PostPosted: Thu Dec 20, 2007 8:29 pm    Post subject: VLC paused Reply with quote

I came across this posting while looking for help on scripting VLC.
In another post, I found a script to control VLC (to some extent).
It took me a while to understand, what Jonas meant, so I thought I'd share the result for the next one on the same quest...

Of course you *can* pause VLC. Thats easy.
But because VLC is not advertising its current player status, you don't know if it is playing, or just started and sitting there, waiting for something to happen.

Why is that important?
Because *if* it's *playing* you could nicely pause it when a call comes in, and unpause it after the call. Perfect.
But if it is *not playing*, then you would *unpause* it when the call comes in - which is exactly the thing we *don't* want. And of course, as soon as you hang up, it'll be paused again. *sigh*

By looking closely at VLC, i found a way to *pause* it, *whenever* a call comes in. If it was paused already, nothing happens. If it's playing, it's paused. That's a big step in the right direction.

Unfortunately we are not quite there yet, because as we don't know if VLC had been playing before the call (or not), we don't know if to unpause (or not).
To be able to detect that, it would be necessesary for VLC to advertise it's status. Which it doesn't. q.e.d.

I've taken the VLC script that floats around somewhere here, and adopted it so it pauses VLC when a call comes in (or when I leave the computer). It stops there, though, not caring about VLC when the call is terminated.

If there was a way to get feedback (return value) on pausing, we could make it. Until then, I hope the VLC developers can be persuaded to do something about their mediocre AppleScript implementation.

Cheers.
Back to top
View user's profile Send private message
snarb
Senior Member


Joined: 04 Aug 2004
Posts: 89

PostPosted: Fri Dec 28, 2007 7:17 pm    Post subject: Reply with quote

If you consider this feature indispensable, you may find [url=http://snarb.co.uk/clicker]VLC Controller[/url] worth the shareware fee.
(If not, at least you know what you are trying to achieve is possible.)
Back to top
View user's profile Send private message
maelcum
Junior Member


Joined: 09 Dec 2007
Posts: 35

PostPosted: Thu Jan 10, 2008 11:04 pm    Post subject: Surely not. Reply with quote

Well snarb,

I would have thought about it. In fact i came across your site while googleing for help.
But I don't like the way you use this forum to advertise your software (I've looked up some of your earlier posts, too). I find it cheap. Just my opinion, of course, and as long as Jonas Salling is tolerating you, things won't change.
Back to top
View user's profile Send private message
snarb
Senior Member


Joined: 04 Aug 2004
Posts: 89

PostPosted: Thu Jan 10, 2008 11:14 pm    Post subject: Reply with quote

Sorry to hear that. Just trying to help, by pointing you to a working solution as an answer to your question.
Back to top
View user's profile Send private message
maelcum
Junior Member


Joined: 09 Dec 2007
Posts: 35

PostPosted: Thu Jan 10, 2008 11:27 pm    Post subject: Reply with quote

...but [i]of course[/i] you were... :roll:
Back to top
View user's profile Send private message
batchman
Newbie


Joined: 26 Mar 2008
Posts: 5

PostPosted: Wed Mar 26, 2008 2:47 am    Post subject: Reply with quote

I know this is a bit late, but since I just joined the forum I didn't see this earlier. If you want to get the playstate of VLC it is possible without that much trouble. The following is a snippet which takes care of it. It requires "Enable access for assistive devices" to be checked in Universal Access in System Preferences. This is the same requirement as the VLC script mentioned earlier which you have to pay for.
The code is part of a set of scripts I have written to get the same functionality you have to pay for, but for free and with the ability to change things to your own liking. If anyone else is interested I could post it when I have time to tidy it up a bit...

[code:1]
on getPlayerState()
using terms from application "SEC Helper"
try
tell application "System Events"
tell process "VLC"
tell menu bar 1
tell menu bar item "Playback"
tell menu 1
get title of menu item 1
set play_pause_btn to the result
get enabled of menu item 2
set stop_enabled to result
end tell
end tell
end tell
end tell
end tell
if stop_enabled is true and play_pause_btn is "play" then
set playstate to paused
else if stop_enabled is false and play_pause_btn is "play" then
set playstate to stopped
else
set playstate to playing
end if
return playstate
on error
return stopped
end try
end using terms from
end getPlayerState
[/code:1]
Back to top
View user's profile Send private message
maelcum
Junior Member


Joined: 09 Dec 2007
Posts: 35

PostPosted: Wed Mar 26, 2008 7:01 am    Post subject: Wohoooo!! Reply with quote

Wohoooo!!!
Checking the change of the menu item. Smart!
I didn't even realize this changes... :roll:

You made my day! This is great! Thank you. So much!

btw: "Playback" would have to be localized for non-english VLC's.
Back to top
View user's profile Send private message
batchman
Newbie


Joined: 26 Mar 2008
Posts: 5

PostPosted: Wed Mar 26, 2008 12:39 pm    Post subject: Reply with quote

Glad to help :) That's true, I've considered doing that automatically, but I haven't had time, if you do it please post the code.

Here is another approach which should work without localization, if you use strange skins this could need some search-functionality to locate the correct buttons though.

Also note that none of these examples work if you're using Spaces and VLC is in another Space than the current one it won't work. For it to work with Spaces you will have to set VLC to be displayed in all. Any suggestions on how to fix this?

[code:1]
on getPlayerState2()
using terms from application "SEC Helper"
try
tell application "System Events"
tell process "VLC"
tell window "VLC - Controller"
get help of button 5
set play_pause_btn to the result
get enabled of button 6
set stop_enabled to result
end tell
end tell
end tell
if stop_enabled is true and play_pause_btn is "play" then
set playstate to paused
else if stop_enabled is false and play_pause_btn is "play" then
set playstate to stopped
else
set playstate to playing
end if
return playstate
on error
return stopped
end try
end using terms from
end getPlayerState2
[/code:1]
Back to top
View user's profile Send private message
maelcum
Junior Member


Joined: 09 Dec 2007
Posts: 35

PostPosted: Wed Mar 26, 2008 6:30 pm    Post subject: Reply with quote

[quote]For it to work with Spaces you will have to set VLC to be displayed in all. Any suggestions on how to fix this?[/quote]
I'm not (yet) using Leopard, but maybe bringing VLC to the front would help. Like this:
[code:1]
...
tell process "VLC"
activate
delay 1
tell window "VLC - Controller"
...[/code:1]
Back to top
View user's profile Send private message
batchman
Newbie


Joined: 26 Mar 2008
Posts: 5

PostPosted: Wed Mar 26, 2008 6:38 pm    Post subject: Reply with quote

That helps, but it also changes the current Space to the one containing VLC. Which could be an annoyance... Actually you don't even have to use a delay for it to work since System Events changes to the new context immediately.
Back to top
View user's profile Send private message
maelcum
Junior Member


Joined: 09 Dec 2007
Posts: 35

PostPosted: Wed Mar 26, 2008 11:11 pm    Post subject: Reply with quote

[quote] Actually you don't even have to use a delay for it to work since System Events changes to the new context immediately.[/quote]
I know. It's for VLC, not the System Event Handler.

This works for me. It's a Proximity Script. Means, it handles VLC when the phone is within/not within reach. It does (deliberately) *not* do anything when a call comes in. I like that to be handled by a different script.

Yes, the code is weird. Yes, it certainly could be more elegant. Yes, I have nil AppleScript knowledge. But you know what? It works! :-)

batchman: Thanks a lot! You made my day!!


[code:1]----
-- Proximity Control VLC Player
-- by ??? from the Salling forum
-- modifications by maelcum
-- VLC Player State Detection by batchman
-- Version 1.4
----

----
-- For this script to work, VLC needs to be configured accordingly:
-- Activate: Settings > Enhanced Options
-- Change Settings > Interface > Hotkeys > Pause only: Alt-p
-- Change Settings > Interface > Hotkeys > Play only: p
----

-- Volume should be controlled by a Phone Control System Volume.scpt
-- The following script is meant for a german system. See VLC_...-Properties for translation.


property should_reactivate_VLC_playing : false
property VLC_WindowTitle_Controller : "VLC - Steuerung" -- would be "VLC - Controller" for an english VLC.app
property VLC_ButtonTitel_Play : "Wiedergabe" -- would be "play" for an english VLC.app


using terms from application "SEC Helper"

on process leaving proximity a_terminal
set should_reactivate_VLC_playing to my pause_VLC_if_playing()
end process leaving proximity


on process entering proximity a_terminal
if should_reactivate_VLC_playing is true then
tell application "VLC"
activate -- Bring window to front
delay 1
tell application "System Events" to key code 35 -- Space key pauses *and* unpauses VLC, so we use "p" as a special key for 'play only';
end tell
end if
end process entering proximity


on pause_VLC_if_playing()
set the process_flag to check application availability "VLC"

if the process_flag then
try

tell application "System Events"
tell process "VLC"
tell window VLC_WindowTitle_Controller
get help of button 5
set play_pause_button_status to the result
get enabled of button 6
set stop_button_status to result
end tell
end tell
end tell
-- Yes, the following lines could be rephrased, thus compressing the whole business, but it's here in verbose for the lecture...
if stop_button_status is true and play_pause_button_status is VLC_ButtonTitel_Play then
return false -- VLC has already been paused; remember to leave things as they are when returning later
else if stop_button_status is false and play_pause_button_status is VLC_ButtonTitel_Play then
return false -- VLC has already been stopped; remember to leave things as they are when returning later
else
tell application "VLC"
activate -- Bring window to front
tell application "System Events" to key code 35 using {option down} -- Space key pauses *and* unpauses VLC, so we use "Alt-p" as a special key for 'pause only'; source: http://hohabadu.de/?APPLESCRIPT/UIScripting
return true -- Remember to start VLC again
end tell
end if

on error
return false -- Somehow we can't find out the current player status; don't do anything when returning...
end try
end if
end pause_VLC_if_playing

end using terms from
[/code:1]
Back to top
View user's profile Send private message
batchman
Newbie


Joined: 26 Mar 2008
Posts: 5

PostPosted: Sat Mar 29, 2008 4:16 pm    Post subject: Reply with quote

I have no comments on how the code is written, what I have written myself is my first attempt at using AS... I just applied the same thinking as I do when programming in other languages.
When I get around to it I think I will make your code part of the new VLC-player I'm working on, if that is ok by you? When it's ready I'll publish it here. I plan to have most of the functionality of the one you have to pay for. I'm almost there, just need a way to read which Hotkeys are mapped to which functions and also a good way of browsing files. Any suggestions here?

I have most of the functionality I want this far:
[list]* Display name of title being played
* Position in file
* Approximate length of file
* Playstate
* All keys mapped to the functions I need
* A menu with all extra functions I want to access[/list:u]
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Salling Software Forums Forum Index -> Scripting Salling Clicker for Mac All times are GMT + 2 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group