1 /*****************************************************************************
2 * applescript.m: MacOS X AppleScript support
3 *****************************************************************************
4 * Copyright (C) 2002-2013 VLC authors and VideoLAN
7 * Authors: Derk-Jan Hartman <thedj@users.sourceforge.net>
8 * Felix Paul Kühne <fkuehne at videolan dot org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
29 #import "applescript.h"
30 #import "CoreInteraction.h"
34 /*****************************************************************************
35 * VLGetURLScriptCommand implementation
36 *****************************************************************************/
37 @implementation VLGetURLScriptCommand
39 - (id)performDefaultImplementation {
40 NSString *o_command = [[self commandDescription] commandName];
41 NSString *o_urlString = [self directParameter];
43 if ([o_command isEqualToString:@"GetURL"] || [o_command isEqualToString:@"OpenURL"]) {
45 BOOL b_autoplay = config_GetInt(VLCIntf, "macosx-autoplay");
46 NSURL * o_url = [NSURL fileURLWithPath: o_urlString];
48 [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: o_url];
50 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
54 b_returned = input_AddSubtitle(p_input, [o_urlString UTF8String], true);
55 vlc_object_release(p_input);
62 o_dic = [NSDictionary dictionaryWithObject:o_urlString forKey:@"ITEM_URL"];
63 o_array = [NSArray arrayWithObject: o_dic];
66 [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue: NO];
68 [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue: YES];
77 /*****************************************************************************
78 * VLControlScriptCommand implementation
79 *****************************************************************************/
81 * This entire control command needs a better design. more object oriented.
82 * Applescript developers would be very welcome (hartman)
84 @implementation VLControlScriptCommand
86 - (id)performDefaultImplementation {
87 NSString *o_command = [[self commandDescription] commandName];
88 NSString *o_parameter = [self directParameter];
90 intf_thread_t * p_intf = VLCIntf;
91 playlist_t * p_playlist = pl_Get(p_intf);
93 if ([o_command isEqualToString:@"play"])
94 [[VLCCoreInteraction sharedInstance] playOrPause];
95 else if ([o_command isEqualToString:@"stop"])
96 [[VLCCoreInteraction sharedInstance] stop];
97 else if ([o_command isEqualToString:@"previous"])
98 [[VLCCoreInteraction sharedInstance] previous];
99 else if ([o_command isEqualToString:@"next"])
100 [[VLCCoreInteraction sharedInstance] next];
101 else if ([o_command isEqualToString:@"fullscreen"])
102 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
103 else if ([o_command isEqualToString:@"mute"])
104 [[VLCCoreInteraction sharedInstance] toggleMute];
105 else if ([o_command isEqualToString:@"volumeUp"])
106 [[VLCCoreInteraction sharedInstance] volumeUp];
107 else if ([o_command isEqualToString:@"volumeDown"])
108 [[VLCCoreInteraction sharedInstance] volumeDown];
109 else if ([o_command isEqualToString:@"stepForward"]) {
110 //default: forwardShort
112 int i_parameter = [o_parameter intValue];
113 switch (i_parameter) {
115 [[VLCCoreInteraction sharedInstance] forwardExtraShort];
118 [[VLCCoreInteraction sharedInstance] forwardShort];
121 [[VLCCoreInteraction sharedInstance] forwardMedium];
124 [[VLCCoreInteraction sharedInstance] forwardLong];
127 [[VLCCoreInteraction sharedInstance] forwardShort];
131 [[VLCCoreInteraction sharedInstance] forwardShort];
132 } else if ([o_command isEqualToString:@"stepBackward"]) {
133 //default: backwardShort
135 int i_parameter = [o_parameter intValue];
136 switch (i_parameter) {
138 [[VLCCoreInteraction sharedInstance] backwardExtraShort];
141 [[VLCCoreInteraction sharedInstance] backwardShort];
144 [[VLCCoreInteraction sharedInstance] backwardMedium];
147 [[VLCCoreInteraction sharedInstance] backwardLong];
150 [[VLCCoreInteraction sharedInstance] backwardShort];
154 [[VLCCoreInteraction sharedInstance] backwardShort];
161 /*****************************************************************************
162 * Category that adds AppleScript support to NSApplication
163 *****************************************************************************/
164 @implementation NSApplication(ScriptSupport)
166 - (BOOL)scriptFullscreenMode {
167 vout_thread_t * p_vout = getVoutForActiveWindow();
170 BOOL b_value = var_GetBool(p_vout, "fullscreen");
171 vlc_object_release(p_vout);
175 - (void)setScriptFullscreenMode:(BOOL)mode {
176 vout_thread_t * p_vout = getVoutForActiveWindow();
179 if (var_GetBool(p_vout, "fullscreen") == mode) {
180 vlc_object_release(p_vout);
183 vlc_object_release(p_vout);
184 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
188 return [[VLCCoreInteraction sharedInstance] mute];
192 intf_thread_t *p_intf = VLCIntf;
196 input_thread_t * p_input = pl_CurrentInput(p_intf);
200 input_state_e i_state = ERROR_S;
201 input_Control(p_input, INPUT_GET_STATE, &i_state);
202 vlc_object_release(p_input);
204 return ((i_state == OPENING_S) || (i_state == PLAYING_S));
207 - (int) audioVolume {
208 return ([[VLCCoreInteraction sharedInstance] volume]);
211 - (void) setAudioVolume:(int)i_audioVolume {
212 [[VLCCoreInteraction sharedInstance] setVolume:(int)i_audioVolume];
215 - (int) currentTime {
216 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
217 int64_t i_currentTime = -1;
220 return i_currentTime;
222 input_Control(p_input, INPUT_GET_TIME, &i_currentTime);
223 vlc_object_release(p_input);
225 return (int)(i_currentTime / 1000000);
228 - (void) setCurrentTime:(int)i_currentTime {
230 int64_t i64_value = (int64_t)i_currentTime;
231 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
236 input_Control(p_input, INPUT_SET_TIME, (int64_t)(i64_value * 1000000));
237 vlc_object_release(p_input);
241 - (int) durationOfCurrentItem {
242 return [[VLCCoreInteraction sharedInstance] durationOfCurrentPlaylistItem];
245 - (NSString*) pathOfCurrentItem {
246 return [[[VLCCoreInteraction sharedInstance] URLOfCurrentPlaylistItem] path];
249 - (NSString*) nameOfCurrentItem {
250 return [[VLCCoreInteraction sharedInstance] nameOfCurrentPlaylistItem];